Solved

Perl with windows dos programs

Posted on 2006-06-21
5
314 Views
Last Modified: 2012-08-13
I'm trying to write a snmp script from scratch to retrieve information about the equipments in the network (not using the ready made modules/libraries due to security policy in the organisation).

I've been using $variable = `snmpget ip oid` so the values will be returned to the variable and allow me to write it to a .xls file. This works perfectly for existing equipments until I come upon some equipments which no longer exist int he network. The snmpget command will then return a snmp error message within the Dos Prompt.

Is there anyway I can prevent the error from appearing? Or may I capture the error message so I can write that IP to a invalid equipment excel file.

Any suggestions will be appreciated.
0
Comment
Question by:Daveyz83
[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
  • 4
5 Comments
 
LVL 22

Accepted Solution

by:
pjedmond earned 500 total points
ID: 16950018
 eval {
    variable = `snmpget ip oid`
  };
  if ($@) {
    errorHandler($@);
  }

http://www.perl.com/pub/a/2002/11/14/exception.html

HTH:)
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16950046
I'd normally have suggested the error.pm but as you said, your policy doesn't allow the use of this:(

However, thinking about this, if your security policy is that stringent, surely, it allows the inclusion of code that your company audits. After you have written your code, then it will be audited by someone before it is approved? Why can't you do a similar audit for the error.pm code?

This approach would save re-inventing the wheel, and provided the auditing process is done sensibly, will save your company time and money.

HTH:)
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16950049
... I guess that they've audited perl then ;)  ?
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16950070
...and DOS?

Just trying to highlight an issue to demonstrate how ridiculous it is! Of course, bear in mind that a code audit of this nature is normally *ONLY* valid for the version audited, and that upgrading requires a complete revalidation of the code, unless the update is done via a patch, *PLUS*, the validation should only apply to a local copy (the one that is validated), and this should have a validation date/approval header and associated hash (preferably signed with the validators key)to verify that the module being used is OK to use.

HTH:)
0
 

Author Comment

by:Daveyz83
ID: 16951123
Thanks for all the help rendered, i will give it a try!

With regard to the security concern, all our scripts/programs have to abide to certain structures, hence, my trouble. (seriously I do not see a point too, but heck, at least I learn something new everyday!)

Thanks to everyone.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

759 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