Shell Script to Run Commands on Multiple Servers from One Server

0
49
Shell Script to Run Commands on Multiple Servers from One Server

If you have 100 nodes cluster and you want to find out uptime of all 100 servers. If any tool installed on your node, that can help you to run commands on multiple servers from one server. If tools are not installed what need to do ? Manually executing on each and every server will take long time and not recommended.

To fix this kind of issues we can use SSH connections between the nodes. with this SSH connection feature we can write the script or run the commands on multiple servers from one server.

Steps to Run Commands on Multiple Servers from One Server

  • SSH Should installed on all linux servers
  • SSH connection should enable between one server to multiple servers, that means suppose you have 100 servers, server 1 should able to ssh from server 1 to remaining 99 servers.
  • Once SSH connections established create one file on server 1 and paste the all 100 servers IP address or host names in that file line separated.
  • Now write a script to run commands on multiple servers from one server.

Check Uptime on All servers from one Server

for i in `cat hosts`; do ssh $i -T "hostname; uptime"; done

Check Jar file is available or not on all servers from one server

for i in `cat hosts`; do ssh $i -T "hostname; ls -lt /usr/hdp/hdfs/lib/hadoop.jar"; done

Check User Id is available or not on all servers from one server

for i in `cat hosts`; do ssh $i -T "hostname; id -a hadoopuser"; done

Check /tmp size on all servers from one server

for i in `cat hosts`; do ssh $i -T "hostname; df -h /tmp "; done

Check All Ambari Agents status from Single server

for i in `cat hosts`; do ssh $i -T "hostname; ambari-agent status"; done

The above all are different simple shell script examples to Run Commands on Multiple Servers from One Server. You can change the above script as per your requirements and execute.

LEAVE A REPLY

Please enter your comment!
Please enter your name here