yes sorry, I've actually tried both ways.
I'll just include the lines i'm having problems with again:
my $snmpCommand = "snmpwalk -v 3 -Os -u $userName -a MD5 -A $authPass -l authPriv -x DES -X $privPass $ipAddress $miboid |";
Search Find A Forum Keyword Search
Find An Expert Advanced Search
Programmers > Languages > Perl Forum
Executing unix commands from a Perl file
thread219-455027
Read
New Posts Reply To
This Thread
E-mail It
Print It Next
Thread
carlosAlberto (IS/IT--Manageme) Jan 22, 2003
Hello,
I would like to execute the following unix command from my Perl file:
snmpwalk -v 3 -u testUser -l noAuthNoPriv $ipAddress $miboid
and then display the result to the screen.
How is is possible to execute this command and display the result???????????????
All help greatly appreciated.
Regards,
Carl.
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
Tek-Tips Forums is Member Supported. Click Here to donate.
MikeLacey (MIS) Jan 22, 2003
a couple of different ways
easy:
$a = `your_command`;
print $a;
but not what you'd call flexible....
a bit harder:
open(CMD, "your_command|"

;
while(<CMD>){
print $_;
}
that way you can control how many lines you dislay, edit the content and format of the lines etc
Mike
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
It's like this; even samurai have teddy bears, and even teddy bears get drunk.
Mark this post as a helpful/expert post!
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
marblecat (Programmer) Jan 23, 2003
system("your_command"

;
Mark this post as a helpful/expert post!
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
carlosAlberto (IS/IT--Manageme) Jan 29, 2003
Hi,
I've took the above command a little further but have come up with another error i can't solve.
PROBLEM:
open(RESULTS, "$snmpCommand -v 3 -u testUser -l noAuthNoPriv $ipAddress $miboid | "

;
The command works when it begins without a variable:
open(RESULTS, "snmpwalk -v 3 -u testUser -l noAuthNoPriv $ipAddress $miboid | "

;
I have checked to make sure $snmpCommand contains the value 'snmpwalk' but i still get an error.
I am soooo puzzled.... please help!!
Carl.
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
carlosAlberto (IS/IT--Manageme) Jan 29, 2003
oh
I define the variable as follows, just in case
my ($snmpCommand) = snmpwalk;
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
MikeLacey (MIS) Jan 29, 2003
Should, I think, be:
my ($snmpCommand) = 'snmpwalk';
Mike
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
It's like this; even samurai have teddy bears, and even teddy bears get drunk.
Mark this post as a helpful/expert post!
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
carlosAlberto (IS/IT--Manageme) Jan 29, 2003
Hi Mike,
Thanks for the reply.
I tried that and that doesn't seem to work.
I also tried creating a variable as:
my $command = '$snmpCommand -v 3 -u testUser -l noAuthNoPriv $ipAddress $miboid | ';
open (RESULTS, $command);
which also didn't work.
????
Carl.
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
rosenk (Programmer) Jan 29, 2003
my $command = '$snmpCommand ...'
wouldn't work. Variables don't expand in single quotes.
Try double quotes.
Mark this post as a helpful/expert post!
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
carlosAlberto (IS/IT--Manageme) Jan 29, 2003
Hi,
I tried the previous comment with no success. Here are my commands:
my $snmpCommand = "snmpwalk -v 3 -Os -u $userName -a MD5 -A $authPass -l authPriv -x DES -X $privPass $ipAddress $miboid |";
open (RESULTS, $snmpCommand);
@replyData = <RESULTS>;
To which @replyData is empty.
The following command did work:
open (RESULTS, "snmpwalk -v 3 -Os -u $userName -a MD5 -A $authPass -l authPriv -x DES -X $privPass $ipAddress $miboid |";
But to bring flexibility there is more than 1 type of snmp command.
Thanks for your help.
Carl.