kaka_2 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I have written a script to get the offset valu on a solaris machine. and below is code:
#!/usr/bin/perl use strict; use warnings; my $cmd = "/usr/sbin/ntpq -p"; my @ntpout = grep (/^\*/, `$cmd`); # grep line starting with * sign a +nd put into an array my $file = 'offset.txt'; open (my $fh, '>' $file) or die "Could not open file '$file' $!"; print $fh "@ntpout\n"> close $fh; # Written array output into file my $offset = `cat offset.txt | awk '{print $9}'`; # here expecting 9th + cloumn value in variable $offset print "$offset \n";
raw output of $cmd is:
remote refid st t when poll reach delay offset + disp ====================================================================== +======== LOCAL(0) LOCAL(0) 10 l 34 64 377 0.00 0.000 + 10.01 *gpstime.domain.l .PPS. 1 u 879 1024 377 1.85 -0.02 +5 0.03 hitman.domain.lo 0.0.0.0 16 - - 1024 0 0.00 0.00 +0 16000.0
when i run command "cat offset.txt | awk '{print $9}'"outside of script it gives me exactly "-0.025" but when i debug the script and added a watch for $offset i see it returns "*gpstime.domain.l .PPS. 1 u 879 1024 377 1.85 -0.025 0.03"
What wrong i am doing? -KAKA-
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using Backtick inside perl gives different output
by toolic (Bishop) on Oct 07, 2013 at 16:56 UTC | |
by kaka_2 (Sexton) on Oct 08, 2013 at 17:09 UTC | |
|
Re: using Backtick inside perl gives different output
by johngg (Canon) on Oct 07, 2013 at 18:01 UTC | |
|
Re: using Backtick inside perl gives different output
by Laurent_R (Canon) on Oct 07, 2013 at 16:59 UTC | |
|
Re: using Backtick inside perl gives different output
by ig (Vicar) on Oct 07, 2013 at 18:25 UTC | |
by kaka_2 (Sexton) on Oct 08, 2013 at 17:11 UTC | |
|
Re: using Backtick inside perl gives different output
by AnomalousMonk (Archbishop) on Oct 07, 2013 at 23:01 UTC | |
|
Re: using Backtick inside perl gives different output
by jwkrahn (Abbot) on Oct 07, 2013 at 23:33 UTC |