• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 488
  • Last Modified:

Perl Net::Telnet and multiple devices

I have a nice little Net::Telnet script that we want to use to remotely reboot devices,  works great for a single IP address.  What I need is to somehow make it read the IP addresses from a text file containing a bunch of IP addresses.  My script is:

use Net::Telnet ();
$machine = '';
$logfile = ".log";
$interval = "20";
$t = new Net::Telnet (Timeout => 10);
$t->waitfor('/Login: $/');
$t->waitfor('/Password: $/');
$t->cmd ("reboot");
$count = 0;
while ($count < $interval) {
        print "...wait...\n";

I know I have to change either the "$machine = '';" line or the "$t->open($machine);" line to make it look to an outside file, but I don't know how to do that.  I'm sadly very green at this.  It would be nice if somehow it could be made to do them one at a time as well, instead of all at once since we possibly could do this to several hundred devices at a time.  Thank you very much for any and all assistance!
1 Solution
Pieter JordaanCommented:

The easiest way to do that, is to run your current script from another script.

$machine = $1;

Save it, then create your text file with all the ip addresses.

then execute the script from bash.
This example uses:
addresseslist - the name of your file containing a list of ip or hostnames, one on each line.
scriptname.pl - the name of the perl script.

for i in `cat addresseslist`; do perl scriptname.pl $i; done

This will do them one at a time.

You can also make it check for failures, and email you the result, using bash scripting.
NCTC-NETAuthor Commented:
I had to make 1 small change but this was exactly the solution I was looking for, thanks!

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now