Execute commands on Multiple UNIX servers
To get the output from single server we can get it very easily by just executing particular command but what if we would like execute commands on multiple UNIX servers.
Use ssh to fulfill above requirement of remote execution.
System Scenario:
kalwa1 ip 192.168.216.130
kalwa2 ip 192.168.216.131
SSH client is a program for logging into a remote machine and for executing commands on a remote machine. If command is specified, command is executed on the remote host instead of a login shell.
By using ssh client we can execute remote command on server.(username is ‘manmohan’)
$ ssh manmohan@192.168.216.131 df
Above command will gather up all mount point information. However if you put this command in script to gather information from three server as follows it will prompt for a password:
ssh manmohan@192.168.216.131 df
ssh manmohan@192.168.216.132 df
ssh manmohan@192.168.216.133 df
In order to avoid this situation we need to configure password less ssh login. Please follow below link.
HOW TO CONFIGURE PASSWORD LESS SSH LOGIN.
Now execute below commands to gather mount point information from all the three servers.
SERVERS_LIST=”192.168.216.131 192.168.216.132 192.168.216.133″
for i in $SERVERS_LIST
do
echo “——————————–” >> df_info
echo “* HOST: $i ” >> df_info
echo “——————————–” >> df_info
ssh manmohan@$i df >> df_info
done
and finally all mount point details can be collected from the “df_info” file.