From: K K on
All

bash-2.03$ cat /tmp/output/1settmp
192.168.112.14 192.168.4.14
192.168.112.16 192.168.4.16

I have entries like the above in the file /tmp/output/1settmp

In the above file I have to take the first column entry(IP) and ssh
into that and has to ping the corresponding second column ip

Wrote a script like this

while read line; do echo $line | ssh -t `awk '{print $1}'` -l user "/
bin/ping -c 4 `awk '{print $2}`"; done < /tmp/output/1settmp

also this one

while read line; do echo $line | ssh -t `cut -d' ' -f1` -l user "/bin/
ping -c 4 `cut -d' ' -f2`"; done < /tmp/output/1settmp

But the problem here is script is taking first column properly but it
is not taking the second column.
Always its like second column is empty.

I tried exporting the variable (line) but it didnt help (as they are
different machines) and also tried escape character like awk '{print \
$2}' no luck

Please any help on this.

Thanks
From: Alan Curry on
In article <f39dad35-0458-49a0-a43e-47698f951b51(a)v41g2000yqv.googlegroups.com>,
K K <mail2rkarthik(a)gmail.com> wrote:
>
>Wrote a script like this
>
>while read line; do echo $line | ssh -t `awk '{print $1}'` -l user "/
>bin/ping -c 4 `awk '{print $2}`"; done < /tmp/output/1settmp

Let me clean that up for you...

while read pinger pingee; do
ssh -t $pinger -l user "ping -c 4 $pingee" < /dev/null
done < thefile

>also this one
>
>while read line; do echo $line | ssh -t `cut -d' ' -f1` -l user "/bin/
>ping -c 4 `cut -d' ' -f2`"; done < /tmp/output/1settmp
>
>But the problem here is script is taking first column properly but it
>is not taking the second column.
>Always its like second column is empty.

Of course the second `...` is empty. The first one has already read the line
from the pipe. There's nothing left for the second cut or awk to read.

--
Alan Curry
From: K K on
Thanks for the reply.
Is there any work around for this.

Thanks
Karthik

On Aug 12, 6:22 am, pac...(a)kosh.dhis.org (Alan Curry) wrote:
> In article <f39dad35-0458-49a0-a43e-47698f951...(a)v41g2000yqv.googlegroups..com>,
> K K  <mail2rkart...(a)gmail.com> wrote:
>
>
>
> >Wrote a script like this
>
> >while read line; do echo $line |  ssh -t `awk '{print $1}'` -l user "/
> >bin/ping -c 4 `awk '{print $2}`"; done < /tmp/output/1settmp
>
> Let me clean that up for you...
>
> while read pinger pingee; do
>   ssh -t $pinger -l user "ping -c 4 $pingee" < /dev/null
> done < thefile
>
> >also this one
>
> >while read line; do echo $line |  ssh -t `cut -d' ' -f1` -l user "/bin/
> >ping -c 4 `cut -d' ' -f2`"; done < /tmp/output/1settmp
>
> >But the problem here is script is taking first column properly but it
> >is not taking the second column.
> >Always its like second column is empty.
>
> Of course the second `...` is empty. The first one has already read the line
> from the pipe. There's nothing left for the second cut or awk to read.
>
> --
> Alan Curry

From: K K on
I had made some modification in the script

while read line; do a=`echo $line|awk '{ print $1}'`; b=`echo $line|
awk '{ print $2}'`; ssh $a -l tiki "ping -c 4 $b"; done < /tmp/output/
1settmp

But it still misses out the second pair 192.168.112.16 192.168.4.16

But the first pair is working fine 192.168.112.14 192.168.4.14 from
the file /tmp/output/1settmp.

Its like the script lost the control after doing ssh.

Any suggestions on this.

Thanks
Karthik

On Aug 12, 6:22 am, pac...(a)kosh.dhis.org (Alan Curry) wrote:
> In article <f39dad35-0458-49a0-a43e-47698f951...(a)v41g2000yqv.googlegroups..com>,
> K K  <mail2rkart...(a)gmail.com> wrote:
>
>
>
> >Wrote a script like this
>
> >while read line; do echo $line |  ssh -t `awk '{print $1}'` -l user "/
> >bin/ping -c 4 `awk '{print $2}`"; done < /tmp/output/1settmp
>
> Let me clean that up for you...
>
> while read pinger pingee; do
>   ssh -t $pinger -l user "ping -c 4 $pingee" < /dev/null
> done < thefile
>
> >also this one
>
> >while read line; do echo $line |  ssh -t `cut -d' ' -f1` -l user "/bin/
> >ping -c 4 `cut -d' ' -f2`"; done < /tmp/output/1settmp
>
> >But the problem here is script is taking first column properly but it
> >is not taking the second column.
> >Always its like second column is empty.
>
> Of course the second `...` is empty. The first one has already read the line
> from the pipe. There's nothing left for the second cut or awk to read.
>
> --
> Alan Curry

From: Ben Bacarisse on
Top posting is bad. :-( I've re-ordered your reply.

K K <mail2rkarthik(a)gmail.com> writes:
> On Aug 12, 6:22 am, pac...(a)kosh.dhis.org (Alan Curry) wrote:
>> In article <f39dad35-0458-49a0-a43e-47698f951...(a)v41g2000yqv.googlegroups.com>,
>> K K  <mail2rkart...(a)gmail.com> wrote:
>> >Wrote a script like this
>>
>> >while read line; do echo $line |  ssh -t `awk '{print $1}'` -l user "/
>> >bin/ping -c 4 `awk '{print $2}`"; done < /tmp/output/1settmp
>>
>> Let me clean that up for you...
>>
>> while read pinger pingee; do
>>   ssh -t $pinger -l user "ping -c 4 $pingee" < /dev/null
>> done < thefile

When Alan said "tidy" up he did not mean simply re-writing your
non-working script in another form. He was giving a the solution.

>> >also this one
>>
>> >while read line; do echo $line |  ssh -t `cut -d' ' -f1` -l user "/bin/
>> >ping -c 4 `cut -d' ' -f2`"; done < /tmp/output/1settmp
>>
>> >But the problem here is script is taking first column properly but it
>> >is not taking the second column.
>> >Always its like second column is empty.
>>
>> Of course the second `...` is empty. The first one has already read the line
>> from the pipe. There's nothing left for the second cut or awk to
>> read.
>
> Thanks for the reply.
> Is there any work around for this.

This part was just an explanation of why your version would not work.
The fix is as above.

--
Ben.
 |  Next  |  Last
Pages: 1 2
Prev: mktemp for directories
Next: Search for 2 strings