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 4 Weeks 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; 4 Weeks Ago at 09:12 AM..
# 2  
Old 4 Weeks 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; 4 Weeks Ago at 09:25 AM..
The Following User Says Thank You to Scrutinizer For This Useful Post:
jim mcnamara (4 Weeks Ago)
# 3  
Old 4 Weeks 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
How can we connect multiple servers at a time? sonu pandey UNIX for Dummies Questions & Answers 0 11-16-2015 09:50 AM
Run a script on multiple servers tdubb123 Shell Programming and Scripting 1 06-23-2015 04:37 PM
Noc for multiple nagios servers eugenes18t Infrastructure Monitoring 0 11-27-2012 05:20 PM
SSH into multiple linux servers xytiz UNIX for Dummies Questions & Answers 7 03-09-2011 06:30 PM
Help with dial-up to multiple ppp servers LAVco Shell Programming and Scripting 6 09-17-2010 12:05 PM
Help Me - How to grep in multiple servers prasad00124 UNIX for Advanced & Expert Users 7 06-24-2009 10:29 AM
Script ftp multiple servers Esquizo000 Shell Programming and Scripting 2 03-18-2009 09:19 AM
rsh to change multiple ip in multiple servers? kenshinhimura Shell Programming and Scripting 2 02-18-2008 03:04 AM
User add on multiple servers sandeep_pan Shell Programming and Scripting 6 06-10-2005 06:04 PM
ftp to multiple servers kristy Shell Programming and Scripting 2 12-03-2001 03:49 PM


All times are GMT -4. The time now is 12:34 PM.

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