Advertisement
Typhoon

SSH Run Remote Command

Jun 30th, 2014
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.99 KB | None | 0 0
  1. # This script can be used to run commands on remote machines.
  2. # You can run commands or copy files over SCP
  3. # Tested on MAC OS and RHEL 7
  4. # Save as script.sh and write IP/Hostnames to external file example hosts.txt
  5. # Run /home/user/script.sh hosts.txt
  6.  
  7. #!/bin/bash
  8. while read line
  9. do
  10.     ssh root@"$line" "hostname; yum install net-snmp net-tools -y;" < /dev/null
  11.     #scp /home/user/local_authorized_keys root@"$line":/root/.ssh/authorized_keys
  12. done < "$1"
  13.  
  14.  
  15.  
  16. ##################################################
  17. ####### Working Example script + hosts.txt #######
  18. ##################################################
  19.  
  20.  
  21. # cat /home/typhoon/script.sh
  22.  
  23. #!/bin/bash
  24. while read line
  25. do
  26.  
  27. #ssh root@"$line" "hostname; yum install net-snmp net-tools -y;" < /dev/null
  28.  
  29. scp /Users/typhoon/Downloads/nanorc root@"$line":/etc/nanorc
  30. scp -rp /Users/typhoon/Downloads/nano root@"$line":/usr/share
  31.  
  32. done < "$1"
  33.  
  34. # cat /home/typhoon/hosts.txt
  35. 192.168.0.10
  36. 192.168.0.11
  37. 192.168.0.12
  38. 192.168.0.13
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement