Slightly_Imperfect
asked on
Perl system command problem
I have wrote a script that reads a file of IP Addresses then if one does not ping run a command. The problem i am getting is that the variables are not showing in the system command.
Program
=======
use Net::Ping;
$infile = "switches.txt";
open (IN, "<$infile") or die "Can't open $infile\n";
while ($line = <IN>) {
@OPCINFO = split(/:/,$line);
$host = "$OPCINFO[0]";
$name = "$OPCINFO[1]";
$service_id = "$OPCINFO[2]";
$p = Net::Ping->new("icmp");
if ($p->ping($host)) {
print "ping ok on ", $name;
}
else {
system 'cmd /c opcmsg s=critical a=ICMP o=$name msg_text="Switch $name is not responding to a Ping" service_id=$service_id';
}
$p->close();
}
close IN;
The $name $service_id $host do not store the variables in the system command !!
Cheers
Mike
Program
=======
use Net::Ping;
$infile = "switches.txt";
open (IN, "<$infile") or die "Can't open $infile\n";
while ($line = <IN>) {
@OPCINFO = split(/:/,$line);
$host = "$OPCINFO[0]";
$name = "$OPCINFO[1]";
$service_id = "$OPCINFO[2]";
$p = Net::Ping->new("icmp");
if ($p->ping($host)) {
print "ping ok on ", $name;
}
else {
system 'cmd /c opcmsg s=critical a=ICMP o=$name msg_text="Switch $name is not responding to a Ping" service_id=$service_id';
}
$p->close();
}
close IN;
The $name $service_id $host do not store the variables in the system command !!
Cheers
Mike
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Nothing has happened on this question in over 8 months. It's time for cleanup!
My recommendation, which I will post in the Cleanup topic area, is to
accept answer by PC_User321.
Please post any comments here within the next seven days. Moderators check comments here before acting on the recommendation. Experts: silence will likely be taken as assent.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jmcg
EE Cleanup Volunteer
My recommendation, which I will post in the Cleanup topic area, is to
accept answer by PC_User321.
Please post any comments here within the next seven days. Moderators check comments here before acting on the recommendation. Experts: silence will likely be taken as assent.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jmcg
EE Cleanup Volunteer
ASKER
system "cmd /c opcmsg s=critical n=$name a=ICMP o=$name msg_text=",'Switch $name is not
responding to a Ping"',"service_id=$servic
Cheers