如何在Unix Shell脚本中进行并行处理?
我有一个 shell 脚本,用于将 build.xml 文件传输到远程 unix 计算机 (devrsp02) 并在该计算机上执行 ANT 任务 wldeploy (devrsp02)。现在,此 wldeploy 任务大约需要 15 分钟才能完成,并且在运行时,unix 控制台的最后一行是 -
“任务{某些数字}已初始化”。
该任务完成后,我们会收到“任务已完成”消息,并且脚本中的下一个任务仅在此之后执行。
但有时,weblogic 域可能存在问题,并且部署可能在内部失败,但不会影响 wldeploy 任务的状态。 unix 控制台仍将停留在“任务{某些数字}已初始化”处。部署的错误将记录在名为 output.a 的文件中。
所以,我现在想要的是 -
在运行 wldeploy 之前启动一个时间计数器。如果 wldeploy 运行超过 15 分钟,则应运行以下命令 -
tail -f output.a ## 不终止 wldeploy
或
cat output.a ## 强制终止 wldeploy 后
这里需要注意的是 - 我无法在后台运行 wldeploy 任务,因为在这种情况下,用户将无法知道任务何时完成,这一点至关重要对于这个脚本。
您能提出什么建议来实现这一目标吗?
I have a shell script that transfers a build.xml file to a remote unix machine (devrsp02) and executes the ANT task wldeploy on that machine (devrsp02). Now, this wldeploy task takes around 15 minutes to complete and while this is running, the last line at the unix console is -
"task {some digit} initialized".
Once this task is complete, we get a "task Completed" msg and the next task in the script is executed only after that.
But sometimes, there might be a problem with the weblogic domain and the deployment might be failing internally, with no effect on the status of the wldeploy task. The unix console will still be stuck at "task {some digit} initialized". The error of the deployment will be getting logged in a file called output.a
So, what I want now is -
Start a time counter before running wldeploy. If the wldeploy runs for more than 15 minutes, the following command should be run -
tail -f output.a ## without terminating the wldeploy
or
cat output.a ## after terminating the wldeploy forcefully
Point to be noted here is - I can't run the wldeploy task in background, as in that case the user won't get to know when the task is complete, which is crucial for this script.
Could you please suggest anything to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建此脚本(例如
deploy.sh
):然后从控制台
然后运行
该脚本将启动一个计数器(15 分钟),如果
wldeploy
进程被强制终止,该计数器将强制终止该进程。正在运行,如果该进程正在运行,您将看到output.a
的内容。如果脚本已终止,则
pkill
将不会返回 true,并且output.a
将不会显示。我会将此任务称为监视而不是“并行处理”:)
Create this script (
deploy.sh
for example):Then from the console
Then run
This script will start a counter (15 minutes) that will forcibly kill the
wldeploy
process if it's running, and if the process was running you'll see the contents ofoutput.a
.If the script has terminated then
pkill
will not return true andoutput.a
will not be shown.I would call this task monitoring rather than "parallel processing" :)
这只会终止它启动的 wldeploy 进程,告诉您 wldeploy 是否返回成功或失败,并在 wldeploy 完成后运行不超过 30 秒。
它应该是 sh 兼容的,但是我现在可以访问的 /bin/sh 似乎有一个损坏的等待命令。
This will only kill the wldeploy process it started, tell you whether wldeploy returned success or failure, and run no more than 30 seconds after wldeploy finishes.
It should be sh-compatible, but the /bin/sh I've got access to now seems to have a broken wait command.
对于不终止 wldeploy 的部分很简单,只需在之前执行
对于终止 wldeploy 的部分,它更复杂,因为您已经确定了 wldeploy 进程的 PID。 pra的答案正是这样做的,所以我就参考一下。
For the part without terminating the wldeploy it is easy, just execute before
For the part with kill it, it is more complex, as you have determine the PID of the wldeploy process. The answer of pra is exactly doing that, so I would just refer to that.