Execute Commands on Multiple Linux or UNIX Servers

This source code is from- http://www.cyberciti.biz/tips/execute-commands-on-multiple-linux-or-unix-servers.html

You will need to setup SSH Share keys for this script – http://www.cyberciti.biz/tips/ssh-public-key-based-authentication-how-to.html


Bash for Loop Examples : http://www.cyberciti.biz/faq/bash-for-loop/


# Linux/UNIX box with ssh key based login


# SSH User name



# Email

SUBJECT="Server user login report"




# create new file



# connect each host and pull up user listing

for host in $SERVERS


echo "--------------------------------" >>$EMAILMESSAGE

echo "* HOST: $host " >>$EMAILMESSAGE

echo "--------------------------------" >>$EMAILMESSAGE

ssh $USR@$host w >> $EMAILMESSAGE



# send an email using /bin/mail

/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE


Other options

Reference Article - http://www.cyberciti.biz/tips/execute-commands-on-multiple-linux-or-unix-servers-part-ii.html 

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