ssh multiple servers


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers ssh multiple servers
# 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:
# 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"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to apply the update statement in multiple servers on multiple dbs at a time .?

Hi , Can any please help the below requirement on all multiple servers and multiple dbs. update configuration set value='yes' ;1) the above statement apply on 31 Databases at a time on different Ip address eg : 10.104.1.12 (unix ip address ) the above ip box contains 4 db's eg : db... (2 Replies)
Discussion started by: venkat918
2 Replies

2. Shell Programming and Scripting

Find active SSH servers w/ ssh keys on LAN

Hi, I am trying to complete my bash script in order to find which SSH servers on LAN are still active with the ssh keys, but i am frozen at this step: #!/bin/bash # LAN SSH KEYS DISCOVERY SCRIPT </etc/passwd \ grep /bin/bash | cut -d: -f6 | sudo xargs -i -- sh -c ' && cat... (11 Replies)
Discussion started by: syrius
11 Replies

3. UNIX for Beginners Questions & Answers

Ssh script to validate ssh connection to multiple serves with status

Hi, I want to validate ssh connection one after one for multiple servers..... password less keys already setup but now i want to validate if ssh is working fine or not... I have .sh script like below and i have servers.txt contains all the list of servers #/bin/bash for host in $(cat... (3 Replies)
Discussion started by: sreeram4
3 Replies

4. Shell Programming and Scripting

Appending authorized_keys on multiple servers using ssh

Hi I have an ssh 'for' loop script to login and put a key on multiple servers. I need to append a file on each server but the command which works ok from the prompt does not work via the script. I have cat filename | ssh user@servername "cat >>append.file.name" I have tried to 'spawn' this in... (0 Replies)
Discussion started by: Grueben
0 Replies

5. Shell Programming and Scripting

Script to add new users to a group on multiple servers using SSH

Hi Experts, I am new to scripting. We have around 400 Linux servers in our environment. I want to add a new user to a perticular group on all the servers using SSH. Requirements: 1) Need to take the server names from a text file. 2) Login into each server and check whether perticular... (1 Reply)
Discussion started by: Satya1983
1 Replies

6. IP Networking

Cant SSH Solaris servers

Hi all. Im working in a telco Environment and recently setup a new server. The other servers are a combination of Solaris + Linux machines. Using my new server , I can ping all other servers ( solaris + redhat linux ) but the issue lies where I try to ssh. I can only successfully ssh linux... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

7. Shell Programming and Scripting

Shell script to connect to multiple ssh servers

Hello, I have access to several linux servers (mostly centos based) located in a DC in another country. from day to day I need to login to each of them to do some work (they dont have gui/window manager installed, I work only from console), or even to just do a check like df -h for disc usage.... (3 Replies)
Discussion started by: MaRiOsGR
3 Replies

8. Shell Programming and Scripting

connect to multiple servers using SSH and execute commands

Requirement: Run a shell script with below inputs file name checksum path the script should go to multiple servers (around 35) and verify the input cksum and if there is a mismatch display a simple message to the user that cksum verification failed. host details, user id /... (1 Reply)
Discussion started by: amicableperson
1 Replies

9. UNIX for Dummies Questions & Answers

SSH into multiple linux servers

Hi All, Okay, I need help. I need to ssh in to multiple linux servers execute certain commands and get them to email and print on the screen when the script is being executed. So below is my script. Its not working :-(. #!/bin/bash #linux/UNIX box with ssh key based login... (7 Replies)
Discussion started by: xytiz
7 Replies

10. Shell Programming and Scripting

rsh to change multiple ip in multiple servers?

good day. i jsut wanted to know what is the best script or the best way changing a lot of Ip's in all servers. Do you have any idea? im using awk to change IP,what if, you have lots of servers. You need to change it one by one? It will take time to change it manually. (2 Replies)
Discussion started by: kenshinhimura
2 Replies
Login or Register to Ask a Question