如何在 Unix Shell 脚本中进行并行处理? [英] How to do parallel processing in Unix Shell script?

查看:42
本文介绍了如何在 Unix Shell 脚本中进行并行处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 shell 脚本,可以将 build.xml 文件传输到远程 unix 机器 (devrsp02) 并执行 ANT 任务 wldeploy在那台机器上 (devrsp02).现在,这个 wldeploy 任务需要大约 15 分钟才能完成,当它运行时,unix 控制台的最后一行是 -

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 -

任务 {some digit} 已初始化".

"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.

但有时,weblogic 域可能存在问题,部署可能在内部失败,对 wldeploy 任务的状态没有影响.unix 控制台仍然会卡在task {some digit} initialized".部署的错误将记录在一个名为 output.a

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 -

在运行 wldeploy 之前启动一个时间计数器.如果 wldeploy 运行时间超过 15 分钟,则应运行以下命令 -

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 ## 不终止 wldeploy

tail -f output.a ## without terminating the wldeploy

cat output.a ## 强行终止 wldeploy 后

cat output.a ## after terminating the wldeploy forcefully

这里要注意的一点是 - 我无法在后台运行 wldeploy 任务,因为在这种情况下,用户不会知道任务何时完成,这对于此脚本至关重要.

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?

推荐答案

创建此脚本(例如deploy.sh):

#!/bin/sh
sleep 900 && pkill -n wldeploy && cat output.a &
wldeploy 

然后从控制台

chmod +x deploy.sh

然后运行

./deploy.sh

此脚本将启动一个计数器(15 分钟),如果 wldeploy 进程正在运行,它将强制终止该进程,如果该进程正在运行,您将看到 output.a 的内容.

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 of output.a.

如果脚本已经终止,pkill 将不会返回 true,output.a 也不会显示.

If the script has terminated then pkill will not return true and output.a will not be shown.

我会称这个任务为监控而不是并行处理":)

I would call this task monitoring rather than "parallel processing" :)

这篇关于如何在 Unix Shell 脚本中进行并行处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆