They all seem to skip the awk command. For your open example, I am confused.
It gives me the error:

failed opening snmpget No such file or directory at ./test.pl line 5.

Thanks

-----Original Message-----
From: Derek B. Smith [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 28, 2006 10:05 AM
To: Curt Shaffer; Perl List
Subject: Re: odd variable result

try this syntax:


my $test = system ("/usr/bin/snmpget -v1 10.1.11.18
-c secret
.1.3.6.1.4.1.710.7.1.5.1.23.1.13.1|awk '{print $4}'");

or 

my $test = qx(you command above w/no quotes needed);

or 

open (SNMP, "snmpget -v1 10.1.11.18 -c secret
.1.3.6.1.4.1.710.7.1.5.1.23.1.13.1" ) or die "failed
opening snmpget $!";

foreach (<SNMP>) {
   my $test = (split)[4];
}


close SNMP or warn $!;

--- Curt Shaffer <[EMAIL PROTECTED]> wrote:

> List,
> 
>  
> 
> I am trying to set a variable based on a system
> call. Here is my code:
> 
>  
> 
> #!/usr/bin/perl
> 
>  
> 
> use strict;
> 
>  
> 
>  
> 
> my $test = system `/usr/bin/snmpget -v1 10.1.11.18
> -c secret
> .1.3.6.1.4.1.710.7.1.5.1.23.1.13.1|awk '{print
> $4}'`;
> 
> print "$test\n";
> 
>  
> 
> When I run that command from the command line it
> works as desired. When I
> run the script with the system command in " rather
> than ` it returns the
> whole value rather than the $4 that I need, then the
> print $test returns 0.
> When I run the script as above the print $test it
> appears to set the
> variable but produces a -1 which is not in the value
> that is returned at
> all. Anyone have some guidance for me on how to do
> this properly?
> 
>  
> 
> Thanks
> 
>  
> 
> Curt
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to