繁体   English   中英

当进程通过脚本运行时,jobs 命令结果为空

[英]jobs command result is empty when process is run through script

我需要通过 shell 脚本在后台运行 rsync,但是一旦它启动,我需要通过 shell 监视这些作业的状态。

脚本退出后, jobs命令在 shell 中运行时返回空。 ps -ef | grep rsync ps -ef | grep rsync显示 rsync 仍在运行。

我可以通过脚本检查状态,但我需要多次运行脚本,因此它使用不同的ip.txt文件进行推送。 所以我不能运行脚本来检查jobs状态。

这是脚本:

for i in `cat $ip.txt`; do
     rsync -avzh $directory/ user@"$i":/cygdrive/c/test/$directory 2>&1 > /dev/null &
done
jobs; #shows the jobs status while in the shell script.
exit 1

shell 脚本退出后, jobs命令的输出为空:

root@host001:~# jobs
root@host001:~# 

可能是什么原因以及如何在rsync在后台运行时获取jobs状态? 我在网上找不到与此相关的文章。

由于您的外壳程序(您从中执行jobs的外壳程序)没有启动rsync ,因此它对此一无所知。 有不同的方法来解决这个问题,但归结为从你的 shell 启动后台进程。 例如,您可以使用source BASH 命令启动您拥有的脚本,而不是在单独的进程中执行它。 当然,您必须在最后删除exit 1 ,否则会退出您的 shell。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM