LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-11-2011, 06:55 AM   #1
greenpool
Member
 
Registered: Sep 2010
Posts: 41

Rep: Reputation: 0
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.
 
Old 09-11-2011, 12:42 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
Use pssh. It's probably in your distribution's package repository.
 
Old 09-11-2011, 12:53 PM   #3
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
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.
 
Old 09-11-2011, 03:19 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
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

Last edited by schneidz; 09-11-2011 at 03:23 PM.
 
Old 09-11-2011, 06:57 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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.
 
Old 09-11-2011, 07:13 PM   #6
-cyrus-
LQ Newbie
 
Registered: Mar 2008
Location: Auckland
Distribution: CentOS (Server), Arch (Laptop)
Posts: 19

Rep: Reputation: 1
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.
 
Old 09-28-2011, 11:06 PM   #7
greenpool
Member
 
Registered: Sep 2010
Posts: 41

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by schneidz View Post
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.
 
Old 09-29-2011, 12:05 AM   #8
snooly
Member
 
Registered: Sep 2011
Posts: 124

Rep: Reputation: Disabled
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/

Last edited by snooly; 09-29-2011 at 12:11 AM. Reason: remove duplicate
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Connect to multiple ssh servers behind a router ?? glenn69 Linux - Networking 2 01-15-2011 08:14 AM
LXer: ssh on multiple servers Using cluster ssh LXer Syndicated Linux News 0 01-11-2008 04:40 PM
SSH to multiple servers DigiCrime Linux - General 6 06-22-2006 09:19 AM
scp/ssh tail(multiple file) remote copy tpreitano Linux - General 1 08-22-2005 03:17 PM
Linking to multiple linux servers with SSH rwalkerphl Linux - Newbie 2 07-05-2004 01:37 PM


All times are GMT -5. The time now is 06:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration