Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

Perl scripting question - issue with quotes- help!

Hello,

I cannot figure out why my perl script is not working.  First of all, if I do an snmpget from the command line like the following:

snmpget -v2c -c csPublic 10.10.20.25 enterprises.9793.1.2.1.1.6.0.\"SYS_DEFINED\".\"g_enteredFrames\".0.0

it returns the appropriate value from the table...

However, if i try putting this in a script like the following:

'snmpget -v2c -c csPublic 10.10.20.25 enterprises.9793.1.2.1.1.6.0.\"SYS_DEFINED\".\"g_enteredFrames\".0.0'

It returns Unknown object identifier (Sub-id not found: enterprises->SYS_DEFINED..0.0)

Is it the quotes in the script that's causing it to not return the value?

0
jewee
Asked:
jewee
  • 5
  • 4
2 Solutions
 
manav_mathurCommented:
'snmpget -v2c -c csPublic 10.10.20.25 enterprises.9793.1.2.1.1.6.0."SYS_DEFINED"."g_enteredFrames".0.0'

or of you are executong it, replace single quotes with backticks.

Manav
0
 
manav_mathurCommented:
or if you *want* to escape double quotes

'snmpget -v2c -c csPublic 10.10.20.25 enterprises.9793.1.2.1.1.6.0.\\"SYS_DEFINED\\".\\"g_enteredFrames\\".0.0'

Manav
0
 
jeweeAuthor Commented:
It didn't work.  It needs the \ in the statement in order to execute.  I also replaced the single quotes with backticks.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
manav_mathurCommented:
Can you show me the line of your code where you are using this??

Manav
0
 
jeweeAuthor Commented:
while (1) {

     
$p1=`snmpget -v2c -c csPublic 10.46.20.247 enterprises.9793.1.2.1.1.6.0.\"SYS_DEFINED\".\"g_enteredFrames\".0.0`;
     chomp($p1);
     print "p1 $p1\n";


   $sleeptime=1-(time%1);
   print time;
   print "\n";
   print "st : $sleeptime\n";
   sleep($sleeptime);
}

After this didn't work, I removed p1 and just tried to execute it.
0
 
manav_mathurCommented:
>I removed p1 and just tried to execute it.

The statement
$p1=`snmpget -v2c -c csPublic 10.46.20.247 enterprises.9793.1.2.1.1.6.0.\"SYS_DEFINED\".\"g_enteredFrames\".0.0`;

will execute the code and store the result in $p1.

Also, did you try the double slash method??

you can also try
$string=qq{snmpget -v2c -c csPublic 10.10.20.25 enterprises.9793.1.2.1.1.6.0.\"SYS_DEFINED\".\"g_enteredFrames\".0.0} ;
my $output=`$string` ;

Manav

0
 
jeweeAuthor Commented:
Still didn't wor.  I also tried the double slash method.  I wrote a bash script which just included that snmpget statement and it returned the correct information.  So, I tried doing the following in my perl script:

while (1) {

     
$p1=`snmpScript.sh`;
     chomp($p1);
     print "p1 $p1\n";


   $sleeptime=1-(time%1);
   print time;
   print "\n";
   print "st : $sleeptime\n";
   sleep($sleeptime);
}
Why is this not working?
By executing the snmpScript alone, it returns the following:

SNMPv2-SMI::enterprises.9793.1.2.1.1.6.0.11.83.89.83.95.68.69.70.73.78.69.68.15.103.95.101.110.116.101.114.101.100.70.114.97.109.101.115.0.0 = STRING: "37501160"

But if I execute the script within the perl script, it returns nothing.
0
 
jeweeAuthor Commented:
Here is my bash script..


#! /bin/bash

     
snmpget -v2c -c csPublic 10.46.20.247 enterprises.9793.1.2.1.1.6.0.\"SYS_DEFINED\".\"g_enteredFrames\".0.0




0
 
manav_mathurCommented:
Funny.
put
use strict ;
use warnings ;

at the beginning of your code.
0
 
TintinCommented:
If you are going to use Perl to do SNMP queries, then why not use a Perl module to do this, otherwise write a shell script.

See http://search.cpan.org/search?query=SNMP&mode=all
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now