?
Solved

Perl system command problem

Posted on 2003-02-26
4
Medium Priority
?
1,049 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:Slightly_Imperfect
[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 Comments
 

Author Comment

by:Slightly_Imperfect
ID: 8024518
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
 
LVL 5

Accepted Solution

by:
PC_User321 earned 200 total points
ID: 8024526
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
 
LVL 20

Expert Comment

by:jmcg
ID: 9692113
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

770 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