Working on multiple servers
If you find yourself having to work on multiple servers, I've found the following for loop quite useful.
for s in server1 server2 server3
do
export s
bash
unset s
done
This puts you in a new shell with the $s
variable (you can call it whatever you like) set to the first server in the list. You can do your bits using $s
to reference the server. After you finish your work on that server, hit CTRL-D to exit that session and you will then be in a new shell with $s
set to the next server in the for loop.
In case you lose track of which shell you are in, just echo $s
. If it shows a servername, you are still within that for loop. If you've quite all the shel sessions, viz. completed the loop, you will find that $s
is empty. I had to put that in for my own safety & sanity :)
Written by Amar Sanakal
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#