parallel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Prefix each line with "input line"


From: Hans Schou
Subject: Prefix each line with "input line"
Date: Sun, 2 Oct 2011 12:15:28 +0200 (CEST)
User-agent: Alpine 2.02 (DEB 1266 2009-07-14)


Hi

I have a number of servers and sometimes I want to check a setting on all of them. Like "what is the default search domain".

For convenience I have all the server names in the environment:
 export srv_all="example.org example.com"
(could be in a file, but environment is always at hand)

Then I get the answer by running:
 parallel ssh {} "grep search /etc/resolv.conf" ::: $srv_all
and the output:
 search example.org
 search example.xxx

In the case above I really missing the hostname for the line with "example.xxx" as this is wrong.

To get the hostname (input line) prefixed on each line I have to write a bit more:

parallel echo -n {}: \; ssh {} "grep search /etc/resolv.conf" ::: $srv_all

Then the output become:
 example.org:search example.org
 example.com:search example.xxx
and then I go to example.com and fix the problem.

One problem is that when get more lines than one, e.g. there is more lines which matches my grep, like 'nameserver', then only the first line got the prefix.

The command for that is:
parallel ssh {} grep nameserver /etc/resolv.conf \| sed -e s/^/{}:/ ::: $srv_all

...but "\| sed -e s/^/{}:/" is not that nice to read.

Second is that it would be nice if "echo -n {}: \;" could be a one-character-option.

/hans
--
Horsebakken 78, DK-2400 København NV

reply via email to

[Prev in Thread] Current Thread [Next in Thread]