Home Man
Search
Today's Posts
Register

If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

ssh multiple servers

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

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 1 Week Ago
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. )

Moderator's Comments:
ssh multiple servers Changed rsh to ssh in thread title to avoid confusion

Last edited by Scrutinizer; 1 Week Ago at 08:12 AM..
# 2  
Old 1 Week Ago
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; 1 Week Ago at 08:25 AM..
The Following User Says Thank You to Scrutinizer For This Useful Post:
jim mcnamara (1 Week Ago)
# 3  
Old 1 Week Ago
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"

Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Run a script on multiple servers tdubb123 Shell Programming and Scripting 1 06-23-2015 03:37 PM
Noc for multiple nagios servers eugenes18t Infrastructure Monitoring 0 11-27-2012 04:20 PM
SSH into multiple linux servers xytiz UNIX for Dummies Questions & Answers 7 03-09-2011 05:30 PM
Help with dial-up to multiple ppp servers LAVco Shell Programming and Scripting 6 09-17-2010 11:05 AM
Help Me - How to grep in multiple servers prasad00124 UNIX for Advanced & Expert Users 7 06-24-2009 09:29 AM
Script ftp multiple servers Esquizo000 Shell Programming and Scripting 2 03-18-2009 08:19 AM
Getting disk information from multiple servers coolkid Shell Programming and Scripting 5 06-30-2008 05:10 AM
rsh to change multiple ip in multiple servers? kenshinhimura Shell Programming and Scripting 2 02-18-2008 02:04 AM
User add on multiple servers sandeep_pan Shell Programming and Scripting 6 06-10-2005 05:04 PM
ftp to multiple servers kristy Shell Programming and Scripting 2 12-03-2001 02:49 PM


All times are GMT -4. The time now is 07:49 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password