Run Background Tasks via SSH
The idea here is simple: you need to connect to hosts 1..100 and execute a command in the background. The trick is to make sure the command continues to run after the SSH session terminates. Simply adding the “&” at the end of the command is not the answer here. In the example below we run a loop that connects to hosts node1 through node100 and executes an rsync process in the background, which continues to run even after the SSH session ends.
i=1 while [ $i -le 100 ] do echo "Launching rsync on node${i}" ssh node${i} "nohup rsync -avu /source_dir /target_dir /dev/null 2>&1 &" (( i = i + 1 )) done
We are using the “nohup” command to create a session-independent process and we redirect all stdout and stderr to /dev/null. The script will connect to the first node; start the rsync process in the background; then it will disconnect and move on to the next node, leaving the rsync process running.
2 Comments »
1 Pingbacks »
-
[…] January 6, 2012 at 3:12 pm Leave a comment Run Background Tasks via SSH Submitted by Igor on June 16, 2011 – 12:58 amNo Comment […]
I’m doing a little research into protocols and networks.
So for example if I have a network with Microsoft Windows computers, and Apple Mac computers, what would be the protocols I would need to link these 2 together?
At the moment I have got AppleTalk as the main protocol suite as it can be installed on Windows computers as well at Apple computers. I also know that AFP (AppleTalk Filing Protocol) is in the AppleTalk suite and is for file transfers.
Thanks in advance!
Basiclly a port proxy thats fast