I need to run rsync in background through shell script but once it has started, I need to monitor the status of that jobs through shell.
jobs
command return empty when its run in shell after the script exits. ps -ef | grep rsync
ps -ef | grep rsync
shows that the rsync is still running.
I can check the status through script but I need to run the script multiple times so it uses a different ip.txt
file to push. So I can't have the script running to check jobs
status.
Here is the script:
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
Output of jobs
command is empty after the shell script exits:
root@host001:~# jobs
root@host001:~#
What could be the reason and how could I get the status of jobs
while the rsync
is running in background? I can't find an article online related to this.
Since your shell (the one from which you execute jobs
) did not start rsync
, it doesn't know anything about it. There are different approaches to fixing that, but it boils down to starting the background process from your shell. For example, you can start the script you have using the source
BASH command instead of executing it in a separate process. Of course, you'd have to remove the exit 1
at the end, because that exits your shell otherwise.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.