From: Arcege on
On Aug 12, 12:50 pm, K K <mail2rkart...(a)gmail.com> wrote:
> 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

You are right, it did lose control after the ssh. Because the ssh
reads stdin, in this case the stdin of the while loop - the rest of
the 1settmp file. Use the '-n' option on ssh or redirect stdin from /
dev/null as someone earlier did. And really... don't use the two awk
calls to split the line, use read.

while read addr1 addr2 rest; do ssh -n -l tiki $addr1 "ping -c 4
$addr2"; done </tmp/output/1settmp

-Arcege
From: K K on
Thanks a bunch Alan,Ben,Arcege !!!

I got it.All Solution works !!!

Alan: Sorry missed ur first post/answer

Ben: Thanks for correcting me

Arcege: Thanks for the latest post

Thanks
Karthik


On Aug 13, 12:36 pm, Arcege <arc...(a)gmail.com> wrote:
> On Aug 12, 12:50 pm, K K <mail2rkart...(a)gmail.com> wrote:
>
>
>
> > 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
>
> You are right, it did lose control after the ssh.  Because the ssh
> reads stdin, in this case the stdin of the while loop - the rest of
> the 1settmp file.  Use the '-n' option on ssh or redirect stdin from /
> dev/null as someone earlier did.  And really... don't use the two awk
> calls to split the line, use read.
>
> while read addr1 addr2 rest; do ssh -n -l tiki $addr1 "ping -c 4
> $addr2"; done </tmp/output/1settmp
>
>   -Arcege

First  |  Prev  | 
Pages: 1 2
Prev: mktemp for directories
Next: Search for 2 strings