?
Solved

Perl scripting question - issue with quotes- help!

Posted on 2005-03-03
10
Medium Priority
?
288 Views
Last Modified: 2008-02-26
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
Comment
Question by:jewee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13450100
'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
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13450114
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
 

Author Comment

by:jewee
ID: 13450138
It didn't work.  It needs the \ in the statement in order to execute.  I also replaced the single quotes with backticks.
0
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!

 
LVL 16

Expert Comment

by:manav_mathur
ID: 13450148
Can you show me the line of your code where you are using this??

Manav
0
 

Author Comment

by:jewee
ID: 13450705
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
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13450792
>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
 

Author Comment

by:jewee
ID: 13451034
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
 

Author Comment

by:jewee
ID: 13451051
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
 
LVL 16

Accepted Solution

by:
manav_mathur earned 1400 total points
ID: 13451065
Funny.
put
use strict ;
use warnings ;

at the beginning of your code.
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 600 total points
ID: 13452980
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question