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
Slightly_ImperfectAsked:
Who is Participating?
 
PC_User321Connect With a Mentor Commented:
system "cmd /c opcmsg s=critical a=ICMP o=$name msg_text=\"Switch $name is not responding to a Ping\" service_id=$service_id";
0
 
Slightly_ImperfectAuthor Commented:
Solved it    


system "cmd /c opcmsg s=critical n=$name a=ICMP o=$name msg_text=",'Switch $name is not

responding to a Ping"',"service_id=$service_id";


Cheers
0
 
jmcgOwnerCommented:
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
0
All Courses

From novice to tech pro — start learning today.