0

I believe I have this sort of correct. I can print the variables no problem. When passing the vriables to the ups check script nothing happeneds?

#!/usr/bin/perl
open FILE, "upslist.txt";

while ($line=<FILE>){
if ($line=~/^(.*?),(.*?)$/){
#print "ups:$1 string:$2\n";
do 'check_snmp_mgeups-0.1.pl -H $1 -C $2';
}        
}         

upslist.txt

#ups
ups1.site,upsstring1
ups2.site,upsstring1
ups3.site,upsstring2
ups4.site,upsstring3

Thanks for the help.

1
  • could you post some lines of upslist.txt? Commented Dec 10, 2013 at 15:30

3 Answers 3

5

You're using single-quotes here, which inhibits interpolation:

do 'check_snmp_mgeups-0.1.pl -H $1 -C $2';

Also, you probably wanted to use system here, not do.

system( "check_snmp_mgeups-0.1.pl", "-H", $1, "-C", $2 ) == 0 
   or die "system call to check_snmp_mgeups-0.1.pl failed: $?";

(Edited to use list form of system, and or instead of ||. My C++ was showing.)

Sign up to request clarification or add additional context in comments.

2 Comments

Not sure what I am doing wrong here. I get: system call to check_snmp_mgeups-0.1.pl failed: -1 at ups_crunch line 11, <FILE> line 2.
You might need to put the full path to check_snmp_mgeups-0.1.pl there. Also, if check_snmp_mgeups-0.1pl script isn't marked executable, then you might need to chmod +x it.
0

You could do this with a local copy of @ARGV:

while ($line=<FILE>){
    if ($line=~/^(.*?),(.*?)$/){
        #print "ups:$1 string:$2\n";

        local @ARGV = ("-H", $1, "-C", $2);
        do 'check_snmp_mgeups-0.1.pl';
    }
}

but if you are seriously trying to integrate some functionality from the check_snmp_mgeups-0.1.pl script into your main script, consider a redesign for check_snmp_mgeups-0.1.pl as a reusable module that you can import into your script, and access its functionality through a subroutine call rather than the clunky do FILE mechanism.

Comments

0

You probably mixed quotes here. You need to use ` instead of ':

#!/usr/bin/perl
open FILE, "upslist.txt";

while ($line=<FILE>){
    if ($line=~/^(.*?),(.*?)$/){
        #print "ups:$1 string:$2\n";
        my $result = `check_snmp_mgeups-0.1.pl -H $1 -C $2`;
    }        
}         

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.