Long time member, first time poster. I have researched this issue thoroughly but I have not found a solution to this particular issue.

I work in a NOC and I am responsible for monitoring servers. From time to time I get sent lists with hundreds of IPs that I need to check and get the status of for a report.

While researching this issue I found this script that seemed it would do exactly what I need.



use Net::Ping;
use strict;

open(INFILE, "<", "ip_list") or die("cannot open INFILE:  $!");

my @ip_array = <INFILE>;


open(OUTFILE, ">", "ping_output") or die("unable to write output: $!");


$p = Net::Ping->new();

   if($_ =~ /\d+.\d+.\d+.\d+/)
            print OUTFILE ("$`is responding to ping.\n");
            print OUTFILE ("$`is NOT responding to ping.\n");



I open a command prompt on my local windows machine and I run this command:

plink -ssh username@Ipaddress -pw password (perl) -m C:\Users\path\to\file\LinuxPingScript.pl

My thoughts on formatting the command this way is as follows:

plink -ssh username@Ipaddress -pw password (this successfully logs me into the remote server)

Then I extended it to this:

plink -ssh username@Ipaddress -pw password (hostname;pwd;whoami;perl -e perl)* (this will ssh into the server, and then run the commands: hostname, pwd, whoami, & perl -e perl (this was in effort to start the perl interpreter on the remote server before calling the script with -m)

I get the output from the first 3 commands then I get a blinking cursor under the results of the whoami command.

So now I try to set the path to the local script which you see posted above:

plink -ssh username@Ipaddress -pw password (hostname;pwd;whoami;perl) -m C:\Users\path\to\file\LinuxPingScript.pl

When I run the above command I get this error:

bash: -c: line 0: syntax error near unexpected token -m' bash: -c: line 0:(hostname;perl) -m C:\Users\path\to\file\LinuxPingScript.pl`

Is there another way to start the interpreter before I call the script? Or is there another way to go about this? I have to run the ping test from the remote server that's which I normally access with Putty. But I thought since this could be automated I could use Plink.

I'm pretty new to this and would appreciate any help I can get.

  • 1
    There's nothing Linuxy in that script. Unless your network connectivity varies depending on host (which does happen) you could install perl on your Windows machine and run the perl script directly. – dave_thompson_085 Jan 24 at 7:40

The file specified using PuTTY/Plink -m switch cannot be a shell script. It can contain a list of top-level shell commands only, which are executed one by one. And actually some SSH servers do not even support multiple commands, just one.

If you want to execute a Perl script, you can:

  • Upload it to the server and execute it

    plink -ssh username@Ipaddress -pw password perl ./LinuxPingScript.pl
  • Execute Perl on the server and feed the script to it:

    plink -ssh username@Ipaddress -pw password perl < C:\Users\path\to\file\LinuxPingScript.pl
  • That makes sense. Can you elaborate on the 1st option please? The script requires IP_list.txt to read from when it executes to create the IP_array. So in this scenario would I have to upload ip_list.txt to the remote server before attempting to run the script? Or is there a way to have the script read the list from my local machine and give me the output. Again i really do appreciate the assistance as I'm doing my best to learn this. – HempKnight Jan 24 at 3:03
  • If you change the script to read the list from its standard input, you can do: plink -ssh username@Ipaddress -pw password perl ./LinuxPingScript.pl < IP_list.txt (where IP_list.txt is a local file). – Martin Prikryl Jan 24 at 7:21
  • Thank you again Martin for the reply. For the method you show above: " plink -ssh username@Ipaddress -pw password perl ./LinuxPingScript.pl < IP_list.txt (where IP_list.txt is a local file)." Does IP_list.txt need to live on the linux server I'm ssh'd into? or will this still work if the IP_list.txt file is on my local Windows machine where I'm initiating the connection. – HempKnight Jan 29 at 2:49
  • My comment says that already: "where IP_list.txt is a local file"* == on your local Windows machine - that's the point of my comment. – Martin Prikryl Jan 29 at 6:10
  • I tried to explain that I was new to this so I asked for clarification. If it was clear sir I would not have asked. I do greatly appreciate your assistance in helping me figure this out – HempKnight Jan 30 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.