ssh multiple servers

Login or Register to Reply

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: 2513 10453 ---

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 08:12 AM..
# 2  
Old 10-11-2018
You could try:
while read server <&3
  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 08:25 AM..
This User Gave Thanks to Scrutinizer For This Post:
jim mcnamara (10-11-2018)
# 3  
Old 10-11-2018
The ssh command might NOT return the exit status of the last remote command.
Fix: check the exit status remotely.
ssh -qnx "$server" "
pgrep 'foo' 2>&1 || echo 'process not running'
" || echo "Server not accessible"

Login or Register to Reply

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 12:45 PM
Ssh script to validate ssh connection to multiple serves with status sreeram4 UNIX for Beginners Questions & Answers 3 06-04-2018 09:30 AM
Ssh onto Solaris servers (which uses NIS) psychocandy Solaris 1 04-22-2017 07:02 AM
Appending authorized_keys on multiple servers using ssh Grueben Shell Programming and Scripting 0 03-17-2015 06:16 AM
How to upgrade SSH/SSL on AIX servers? System Admin 77 AIX 1 05-05-2014 03:39 PM
Ssh not working to one server from any of the servers Vishal_dba UNIX for Dummies Questions & Answers 7 04-25-2014 11:56 AM
Script to add new users to a group on multiple servers using SSH Satya1983 Shell Programming and Scripting 1 12-24-2013 12:13 PM
Ssh to an array of servers in a for loop Sree10 Shell Programming and Scripting 9 09-12-2013 12:44 PM
Cant SSH Solaris servers Junaid Subhani IP Networking 3 02-03-2013 08:01 PM
Shell script to connect to multiple ssh servers MaRiOsGR Shell Programming and Scripting 3 07-09-2012 05:52 AM
connect to multiple servers using SSH and execute commands amicableperson Shell Programming and Scripting 1 09-07-2011 11:49 AM
SSH into multiple linux servers xytiz UNIX for Dummies Questions & Answers 7 03-09-2011 05:30 PM
ssh: require passphrase from some servers but not others Squeakygoose UNIX for Advanced & Expert Users 3 07-14-2009 08:30 PM
connecting servers using SSH - help needed senthilkumar_ak Shell Programming and Scripting 12 08-28-2008 05:50 AM
rsh to change multiple ip in multiple servers? kenshinhimura Shell Programming and Scripting 2 02-18-2008 02:04 AM