blc6450vpt1>en Password: blc6450vpt1#conf t Enter configuration commands, one per line. End with CNTL/Z. blc6450vpt1(config)#interface ethernet 1 blc6450vpt1(config-if-eth)# #### #!/usr/bin/perl ## modules to use use strict; use warnings; use Net::Telnet; use Data::Dumper; #$|++; # ## establish some global variables my $HOSTNAME = "10.2.200.10"; my $HOSTPORT = "2033"; my $input_file = 'input.log'; my $output_file = 'output.log'; my $option_file = 'option.log'; my $dump_file = 'dump.log'; my $conn = new Net::Telnet ( Timeout => "3", Errmode => \&error_sub, #Errmode => "return", #Dump_Log => $dump_file, Input_log => $input_file, #Option_log => $option_file, #Output_log => $output_file, Output_record_separator => "", Prompt => '/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/' ); # open connection to host $HOSTNAME and port $HOSTPORT # and die if there is a problem unless ($conn->open(Host => $HOSTNAME, Port => $HOSTPORT)) { die "Error opening socket:: ".$conn->errmsg(); } print "Connected to ".$conn->host().", port ".$conn->port()."\n"; # Force the password prompt to be displayed by sending a ^M $conn->print(" "); $conn->waitfor('/Password:/'); $conn->print("password\n"); #Regex to match most IOS devices $conn->waitfor('/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); $conn->cmd("term length 0\n"); $conn->waitfor('/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); $conn->cmd("term width 120\n"); $conn->waitfor('/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); my @num = $conn->cmd(String => "show clock\n", Prompt => '/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); print Dumper(\@num); print STDERR Dumper(\@num); my @output = (); $conn->print("show version\n"); my (undef, $process_string) = $conn->waitfor('/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); print $process_string . "\n"; print STDERR $process_string; print Dumper($process_string); sub error_sub{ my $error = shift; print "Made it to error method " . Dumper($error, \@_); } #### [prompt]$./Net_Telnet_console.pl Connected to 10.2.200.10, port 2033 Made it to error method $VAR1 = 'pattern match timed-out'; $VAR2 = []; Made it to error method $VAR1 = 'command timed-out'; $VAR2 = []; Made it to error method $VAR1 = 'pattern match timed-out'; $VAR2 = []; Made it to error method $VAR1 = 'command timed-out'; $VAR2 = []; Made it to error method $VAR1 = 'pattern match timed-out'; $VAR2 = []; Made it to error method $VAR1 = 'command timed-out'; $VAR2 = []; $VAR1 = []; Made it to error method $VAR1 = 'pattern match timed-out'; $VAR2 = []; #### Test]$ cat input.log Password: blc6450vpt1>term length 0 blc6450vpt1>term width 120 blc6450vpt1>show clock *13:35:28.043 PST Sat Aug 21 2010 blc6450vpt1>show version ......don't need to paste the rest