Showing posts with label ssh. Show all posts
Showing posts with label ssh. Show all posts

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

Tuesday, 16 November 2010

ssh in a loop

Runs the command 'ls' on several machines and stores the results in output.txt


while read host; do
echo "running on $host"
ssh -n $host "ls " >> output.txt;
done < boxes.txt


where boxes.txt is a file containing a list of machines to ssh to

advanced reading

Alternative:

for loop in {281..284}
do
echo "running on frread@nygeqgd0$loop.us.db.com"
ssh -n frread@nygeqgd0$loop.us.db.com "ls " >> output.txt;
done


2nd Alternative:

for loop in `seq 281 284`

more bash loops