I often come across tasks that need to be done on multiple servers, like fetching OS details or Hardware details. Earlier I used to login to each server individually & fetch details. But this became tedious when the number of servers increased many-folds. So I wrote (took help from a friend as well) this small yet beautiful script to accomplish this task easily. This, however, needs password for each server but this can be sorted out by setting up password-less SSH.
Trick was to include -t switch with ssh. It opens a new pseudo-terminal, executes command there & then exits to open a new pseudo-terminal on next server (from the list mentioned in HOSTS variable)
PS – This script only fetches OS details. But a lot of stuff can be done, depending upon the need 🙂
HOSTS=`cat /home/shashank/servers_list` echo -e "IP\tOS">>osDetails.txt for i in $HOSTS do osName=`ssh -t shashank@$i 'cat /etc/redhat-release'` echo -e "$i\t$osName" >> osDetails.txt done