LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ssh into multiple servers and tail -f (https://www.linuxquestions.org/questions/linux-newbie-8/ssh-into-multiple-servers-and-tail-f-902414/)

greenpool 09-11-2011 05:55 AM

ssh into multiple servers and tail -f
 
Hi there,

got a question about simultaneously running a script on multiple servers..

currently i have to run the following on two servers:

Code:

tail -f /var/logs | grep error
i was considering putting it in a script. but as it might be clear this involves simultaneously ssh-ing into two different boxes and running the above command...can this be done? if so can you please tell me how (with some explanation if its not too much trouble), thanks!

NOTE:i also need to login via ssh/pw..the passwords on both servers are the same.

macemoneta 09-11-2011 11:42 AM

Use pssh. It's probably in your distribution's package repository.

anomie 09-11-2011 11:53 AM

Alternatively, if this is a long term need (i.e. not just a one-off), you might consider appointing one of your servers as a logging host. That would allow you to tail(1) - and report against - a set of logs on just that server.

schneidz 09-11-2011 02:19 PM

not sure why you need to ssh into both at the same time (why not 1-by-1 ?)

not sure why you must use passwords (why not use ssh keys ?)

anyways, i would do something like:
Code:

ssh user1@server1 tail -f /var/logs | grep error && ssh user2@server2 tail -f /var/logs | grep error

chrism01 09-11-2011 05:57 PM

ssh-keys is recommended for this; you really shouldn't be putting passwd in a script, or consider ssh-agent.
If you MUST use passwds, consider Expect http://linux.die.net/man/1/expect.
Another option if this is a regular requirement, can you get the remote machines to do this automatically eg triggered by cron or by an event, then email the results to you.

-cyrus- 09-11-2011 06:13 PM

To make your process quicker, and still log in to each server individually to run your command (paste in your terminal), you can try FastSSHer with your sshkey.

greenpool 09-28-2011 10:06 PM

Quote:

Originally Posted by schneidz (Post 4469051)
not sure why you need to ssh into both at the same time (why not 1-by-1 ?)

not sure why you must use passwords (why not use ssh keys ?)

anyways, i would do something like:
Code:

ssh user1@server1 tail -f /var/logs | grep error && ssh user2@server2 tail -f /var/logs | grep error


How would i use ssh keys? would you know of a simple guide i can follow? I'm still pretty new to all this and a step by step guide would be helpful, thanks.

and thanks to everyone else for their suggestions.

snooly 09-28-2011 11:05 PM

If you do a web search for "automatic login ssh" you will find pages like this:

http://linuxproblem.org/art_9.html

http://wp.uberdose.com/2006/10/16/ssh-automatic-login/


All times are GMT -5. The time now is 12:40 PM.