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-In reply to using Backtick inside perl gives different output by kaka_2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |