Telnet script for switches

Can you imagine telneting into 700+ switches to update just a single line? Well with this script it can be done in a very easy way, it does require Perl and the Net::Telnet::Cisco library.
In this case I used the script to update Alcatel Switches OminiStack but it should also work for Cisco Switches/Routers.

Download here, or copy and paste to and run perl hosts.txt

#!/usr/local/bin/perl -w
# Remote exec commands into a list of switches (Alcatel, OminiStack, Cisco) by telenet
# Author: Felipe Ferreira
# Date 05/09/2008
# Version: 0.3
# tip: open the .logs in gedit, because cat won't display all chars.
use Net::Telnet::Cisco ();

my $username = "admin";
my $passwd = "passnow";

if (!defined($ARGV[0]))
print "n Usage :$0 n";
print "Example: $0 hosts.txtn";
print "n Author: Felipe Ferreira nn";
exit 1;
$filehosts = $ARGV[0];

#Get all hosts IPs from the text file and pass to an array
open(DATA, $filehosts);
@swtichlist= ;
foreach (@swtichlist) {
$host=shift @swtichlist;
$host =~s/t+//;
chomp ($host);

print "Loging to: $host n";

sub TELNET {
$t = Net::Telnet::Cisco -> new (
Timeout => 5,
Binmode => "true",
Prompt => '/#/',
Dump_log => "dump.log",
Input_log => "$host.log");

#Start Connecting
$t->send_wakeup( 'connect' );
$t->cmd('snmp-server community caca rw view DefaultSuper');
$t->send_wakeup( 'connect' );
$t->cmd("copy running-config startup-config");
print "Done, check .log n";

# ref:

2 Thoughts

  1. I cannot get the script to execute. I receive an error.

    perl hosts.txt
    syntax error at line 24, near “= ;”
    Execution of aborted due to compilation errors.

    hosts.txt is a file that includes a list of IP addresses.

    Thanks for any assistance you might have.

Leave a Reply

Your email address will not be published. Required fields are marked *