Unsolved

This post is more than 5 years old

1 Message

9949

September 22nd, 2008 07:00

serial console perl script

Hi all,

 

Last week I was looking for a perl script to collect the switch serial output, as I needed to monitor it during a couple of hours

 

There are a lot of interesting posts in this Forum, although I could not find what I needed, so at the end I decided to try on my own... just in case somebody else comes across the same situation, I will post it

 

hope it helps!!!

 

cheers

 

Cesar

 

 

Pd.- win32::serialport module needed

 

#!c:\perl\bin\perl.exe
# collect serial output from the switch
use Win32::SerialPort;

# Prompt variable needed whenever there are multiple pages

$Port = "COM1";

$Prompt = "pc6224_1";
@Commands = ("sh ver","sh log","sh clock");

# Serial settings
$PortObj = new Win32::SerialPort($Port) || die "Can't open $Port: $^E\n";
$PortObj->databits(8);
$PortObj->baudrate(9600);
$PortObj->parity("none");
$PortObj->stopbits(1);

$PortObj->write("\nend\n");
sleep 1;
my $result = $PortObj->input;
# enable mode
if ( $result =~ m/$Prompt>/ ) { $PortObj->write("enable\n"); sleep 1; $result = $PortObj->input;}
print STDOUT "$result\n";

foreach $comm (@Commands) {
    $PortObj->write("$comm\n");
    sleep 1;
    $result = $PortObj->input;
    while ( not ( $result =~ m/$Prompt/ ) ) {
            $PortObj->write("\ ");
            sleep 1;
            $result .= $PortObj->input;
    }
    print STDOUT "$result\n";
}

No Responses!
No Events found!

Top