#!/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.txt\n"; print "\n Author: Felipe Ferreira \n\n"; exit 1; } $filehosts = $ARGV[0]; chomp($filehosts); #Get all hosts IPs from the text file and pass to an array open(DATA, $filehosts); @swtichlist= ; close(DATA); foreach (@swtichlist) { $host=shift @swtichlist; $host =~s/\t+//; chomp ($host); print "Loging to: $host \n"; &TELNET; } # SUBS sub TELNET { $t = Net::Telnet::Cisco -> new ( Timeout => 5, Binmode => "true", Prompt => '/#/', Dump_log => "dump.log", Input_log => "$host.log"); #Start Connecting $t->open($host); $t->waitfor('/Name:/'); $t->print($username); $t->waitfor('/Password:/'); $t->print($passwd); $t->autopage; $t->always_waitfor_prompt; $t->cmd('config'); $t->waitfor_pause(0.9); $t->send_wakeup( 'connect' ); $t->cmd('snmp-server community sac rw 10.1.2.1 view Super'); $t->send_wakeup( 'connect' ); $t->waitfor_pause(0.9); $t->cmd("exit"); $t->cmd("copy running-config startup-config"); $t->cmd("Yes"); $t->cmd("exit"); $t->close; } print "Done, check .log \n"; # ref: # http://www.ruby-doc.org/stdlib/libdoc/net/telnet/rdoc/classes/Net/Telnet.html # http://nettelnetcisco.sourceforge.net/docs.html#name