A Small Linux Script To Login To Multiple Servers & Get The Details


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
Advertisements

One thought on “A Small Linux Script To Login To Multiple Servers & Get The Details

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s