tweak flush and timeout, better prompt detection
[dell-switch] / dell-switch.pl
index 2a7a89d..4d7badb 100755 (executable)
@@ -35,7 +35,9 @@ sub send_pty {
        foreach (split //, $string) {
                print STDERR "[$_]" if $debug;
                syswrite $pty, $_;
-#              $pty->flush;
+               #$pty->flush;
+               sleep 0.05;
+
                sysread $pty, my $echo, 1;
                print STDERR $echo;
                $buff .= $echo;
@@ -74,6 +76,8 @@ while(1) {
        } elsif ( $buff =~ m/Password:/ ) {
                send_pty "$passwd\n";
                $buff = '';
+       } elsif ( $buff =~ m/\b([\w\-]+)>$/ ) {
+               send_pty "enable\n";
        } elsif ( $buff =~ m/([\w\-]+)#$/ ) {
                my $hostname = $1;
                if ( $buff ) {
@@ -92,7 +96,10 @@ while(1) {
        } elsif ( $buff =~ m/% Unrecognized command/ ) {
                exit 1;
        } elsif ( $buff =~ s{More: <space>,  Quit: q.*One line: <return> }{} ) {
+               sleep 0.5;
                send_pty " ";
+       } elsif ( $buff =~ s{\Q--More-- or (q)uit\E}{} ) {
+               send_pty " "
        } elsif ( $buff =~ s{\e\[0m\r\s+\r}{} ) {
        }
 }
@@ -101,4 +108,4 @@ __DATA__
 show arp
 show vlan
 show running-config
-show bridge address-table
+show bridge address