title: Perl Script to Telnet to multiple IP and send a Reboot command, and print a confirmation to a log file
body: <p>I am trying to write a Perl Script (Never done it before).</p>
  
  <p>Basically this script is to connect to a VoIP phone system and reboot the devices. I want it to connect to each sites device, reboot it and print the devices confirmation that a reboot is occurring or a connection error to a log file. I have no idea what I am doing with Perl and I do not even know if what I have so far is even remotely correct. It is just what I was able to find through digging around on google/forums.</p>
  
  <p>What I want the script to do is the following:</p>
  
  <p>I want the Perl Script to Telnet to a preset list of IP Addresses.</p>
  
  <p>I want a .txt list of the IPs it will connect to (they all use the same login/password).
  or is it possible to include the list within the actual Perl Script, that can be edited in the future to add/remove IP's?</p>
  
  <p>Once the script telnet's, I want it to send the command 'reboot now' and then print the response to a log file along with the IP that it was connected to at the time it sent the command (The response when the command is issued is something like 'System is going down for a reboot now'). I want it to do this for each IP it connects to, and if it is unable to connect I want it to print an error along the lines of 'XXX.XXX.XXX.XXX Unable to Connect'</p>
  
  <p>So the log would look something like this:</p>
  
  <pre><code>XXX.XXX.XXX.101 System going down for reboot
  XXX.XXX.XXX.102 System going down for reboot
  XXX.XXX.XXX.103 Unable to Connect
  XXX.XXX.XXX.104 Unable to Connect
  XXX.XXX.XXX.105 System going down for reboot
  </code></pre>
  
  <p>Is this possible to do?</p>
  
  <p>I currently have this:</p>
  
  <pre><code>#!/usr/bin/perl -w
  use strict;
  use Net::Telnet;
  
  my $log = './log.txt';
  
  $telnet = new Net::Telnet ( Timeout=&gt;10,
  Errmode=&gt;'die'
  Prompt =&gt; '/\$ $/i');
  $telnet-&gt;open('IPADDRESS');
  $telnet-&gt;login('USERNAME', 'PASSWORD');
  print $telnet-&gt;cmd('reboot now');
  writef($log);
  </code></pre>
  
  <p>For the Prompt => do I need to change it to match whatever the symbol is that shows when you telnet and connect to the IP? The symbol I see is # so would the command be:</p>
  
  <pre><code>Promt =&gt; '/\# #/i);
  </code></pre>
  
  <p>Any help would be amazing.</p>