[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problem with tail -f that need to add to each line constant string a
From: |
Bob Proulx |
Subject: |
Re: problem with tail -f that need to add to each line constant string at the beginning of each line |
Date: |
Sat, 29 Oct 2011 11:12:03 -0600 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
dan12341234 wrote:
> im running 4 scripts that perform ssh and tail -f on a file exist on 4
> servers and display on the screen.
> (1 script per servers)
>
> ssh server1 tail -f /var/log/apache/access_log
> ssh server2 tail -f /var/log/apache/access_log
> ssh server3 tail -f /var/log/apache/access_log
> ssh server4 tail -f /var/log/apache/access_log
>
> the problem is that the display dosent show any identification from which
> server each line
>
> what i need is something with an echo servername, before each line printed
> to the screen
There are many specialized programs to do exactly what you are asking
such as dsh (distributed shell) and other tools. You might want to
investigate those.
But you can do what you want by using sed to prepend to the line.
ssh -n server1 'tail -f /var/log/syslog | sed --unbuffered "s/^/$(hostname):
/"'
ssh -n server2 'tail -f /var/log/syslog | sed --unbuffered "s/^/$(hostname):
/"'
You might consider applying the commands as standard input instead. I
think it is easier to avoid quoting problems that way.
echo 'tail -f /var/log/syslog | sed --unbuffered "s/^/$(hostname): /"' | ssh
-T server1
Bob