bash – 跟踪gnu parallel中的状态/进度

我已经在我们的一个主要脚本中实现了并行,以在服务器之间执行数据迁移.目前,输出以漂亮的颜色一次性显示(-u),并根据正在运行的序列执行函数的周期性状态回声(例如5/20:$username:rsyncing homedir或5/20: $username:恢复帐户).这些都直接回显到运行脚本的终端,并在那里积累.但是,根据命令运行的时间长度,输出最终可能会出现故障,并且在shuffle中可能会丢失长时间运行的rsync命令.但是我不想等待长时间运行的进程完成以获得后续进程的输出.

简而言之,我的问题是跟踪正在处理哪些参数并且仍在运行.

我想做的是使用(parallel args command {#} {} ::: $userlist)&并行发送到后台.然后跟踪每个运行功能的进度.我最初的想法是每隔几秒就使用ps和grep与tput一起重写屏幕.我通常并行运行三个作业,所以我希望有一个屏幕显示,例如:

1/20: user1: syncing homedir
current file: /home/user1/www/cache/file12589015.php

12/20: user12: syncing homedir
current file: /home/user12/mail/joe/mailfile

5/20: user5: collecting information
current file: 

我当然可以一起得到上面的状态输出没有问题,但我目前的挂断是将各个并行进程的输出分成三个不同的……管道?变量?文件?这样它就可以解析成上面的信息.

最佳答案 不确定这是否更好:

echo hello im starting now
sleep 1
# start parallel and send the job to the background
temp=$(mktemp -d)
parallel --rpl '{log} $_="Working on@arg"' -j3 background {} {#} ">$temp/{1log} 2>&1;rm $temp/{1log}" ::: foo bar baz foo bar baz one two three one two three :::+ 5 6 5 3 4 6 7 2 5 4 6 2 &
while kill -0 $!  2>/dev/null ; do
    cd "$temp"
    clear
    tail -vn1 *
    sleep 1
done
rm -rf "$temp"

它为每个作业创建一个日志文件.每秒对所有日志文件进行尾部处理,并在作业完成时删除日志文件.

日志文件名为’working on …’.

点赞