执行一个脚本,执行其他脚本时应该上传它的输出

时间:2017-09-07 13:45:21

标签: bash multitasking

我有2个脚本,一个执行任务(生成大量输出),另一个脚本将输出上传到互联网。我想开始执行第一个,并且每5秒上传脚本应该上传输出。当正在执行任务的人完成时,上传脚本也会完成

3 个答案:

答案 0 :(得分:0)

可以有很多可用的选项来实现你所说的。

一个可用的选项是执行

pkill -f script2.sh 

第一个完成后。

更好的方法是创建第三个主脚本来处理script1和script2的开始和停止

答案 1 :(得分:0)

您应该让上传脚本控制任务脚本:

execute_task.sh &
task_pid=$!

# do the preliminary stuff for the upload script

# now, wait until the task is done:
wait "$task_pid"

# then carry on with the upload commands...

答案 2 :(得分:-2)

尝试下面的一些想法:

while true
do
    if [[ `pgrep first.sh | grep -c` == 0 ]];then
        kill -9 `pgrep firsh.sh`
        kill -9 `pgrep second.sh`
        echo "Processes killed"
        break
    fi
    sleep 10
done