ssh multiple servers

Tags
multiple, multiple servers, newbies, rsh, rsh hosts, server, servers

 
Thread Tools Search this Thread
# 1  
Old 10-11-2018
ssh multiple servers

Hi folks.

I'm pretty new to unix, while I'm learning a lot I'm finding bash scripting quite confusing. Im sure it's not really, my head just hasn't clicked with it.

Anyway, I need a script to loop the ip addresses stored in a file and run a "pgrep <process>" and return the pid or some indicator that there wasn't one:
Code:
192.xxx.xxx.055 2513
192.xxx.xxx.056 10453
192.xxx.xxx.067 ---
etc.

Could some kind person please post me a script to do this and explain what's going on?

Many thanks.

------ Post updated at 10:30 AM ------

I should add, I do have ssh keys sent everywhere so passwords aren't a problem. Smilie)

Moderator's Comments:
Mod Comment Changed rsh to ssh in thread title to avoid confusion

Last edited by Scrutinizer; 10-11-2018 at 09:12 AM..
# 2  
Old 10-11-2018
You could try:
Code:
while read server <&3
do
  printf "%s: " "$server"
  ssh -q "$server" pgrep 'foo' 2>&1 || echo "Server not accessible or process not running"
done 3<serverfile

Where "foo" should be replace by the process pattern that you are looking for .

Last edited by Scrutinizer; 10-11-2018 at 09:25 AM..
This User Gave Thanks to Scrutinizer For This Post:
jim mcnamara (10-11-2018)
# 3  
Old 10-12-2018
The ssh command might NOT return the exit status of the last remote command.
Fix: check the exit status remotely.
Code:
ssh -qnx "$server" "
pgrep 'foo' 2>&1 || echo 'process not running'
" || echo "Server not accessible"


|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Find active SSH servers w/ ssh keys on LAN syrius Shell Programming and Scripting 11 11-06-2018 01:45 PM
Ssh script to validate ssh connection to multiple serves with status sreeram4 UNIX for Beginners Questions & Answers 3 06-04-2018 10:30 AM
Ssh onto Solaris servers (which uses NIS) psychocandy Solaris 1 04-22-2017 08:02 AM
Appending authorized_keys on multiple servers using ssh Grueben Shell Programming and Scripting 0 03-17-2015 07:16 AM
Ssh not working to one server from any of the servers Vishal_dba UNIX for Dummies Questions & Answers 7 04-25-2014 12:56 PM
Script to add new users to a group on multiple servers using SSH Satya1983 Shell Programming and Scripting 1 12-24-2013 01:13 PM
Ssh to an array of servers in a for loop Sree10 Shell Programming and Scripting 9 09-12-2013 01:44 PM
Ssh between servers - No DSA host key is known psychocandy Solaris 3 05-21-2013 06:31 AM
Cant SSH Solaris servers Junaid Subhani IP Networking 3 02-03-2013 09:01 PM
Shell script to connect to multiple ssh servers MaRiOsGR Shell Programming and Scripting 3 07-09-2012 06:52 AM
connect to multiple servers using SSH and execute commands amicableperson Shell Programming and Scripting 1 09-07-2011 12:49 PM
SSH into multiple linux servers xytiz UNIX for Dummies Questions & Answers 7 03-09-2011 06:30 PM
ssh: require passphrase from some servers but not others Squeakygoose UNIX for Advanced & Expert Users 3 07-14-2009 09:30 PM
connecting servers using SSH - help needed senthilkumar_ak Shell Programming and Scripting 12 08-28-2008 06:50 AM
rsh to change multiple ip in multiple servers? kenshinhimura Shell Programming and Scripting 2 02-18-2008 03:04 AM