Friday 17 December 2010

SSH to bounce jobs

Code to SSH to another box, kill the old process and bring up a new one.

SSH, source the login file and cd to the right directory:

ssh -f user@somebox " . ./.bashrc; cd /apps/myapp/;


Kills the old process:

cat ../pid | xargs kill;


Calls startMyApp and pipes stdout, stderr to files. Creates a file called pid containing the process ID of this process:

nohup ./startMyApp 1>../stdout 2>../stderr & echo $! > ../pid


Putting it all together:

ssh -f user@somebox " . ./.bashrc; cd /apps/myapp/; cat ../pid | xargs kill; sleep 10; nohup ./startMyApp 1>../stdout 2>../stderr & echo $! > ../pid' > startMyAppRemote.log

No comments:

Post a Comment