added two more commands for ip only invocation
[dell-switch] / dell-switch.pl
index 158c8e4..22d0ddd 100755 (executable)
@@ -19,9 +19,13 @@ my $ip = shift @ARGV || die "usage: $0 IP command[ command ...]\n";
 my @commands = @ARGV;
 @commands = <DATA> unless @commands;
 
-warn "## $ip\n";
-my $ssh = Net::OpenSSH->new('auto@'.$ip);
+warn "\n## ssh $ip\n";
+my $ssh = Net::OpenSSH->new($ip, user => $login, passwd => $passwd);
 my ($pty ,$pid) = $ssh->open2pty();
+if ( ! $pty ) {
+       warn "ERROR: can't connect to $ip, skipping";
+       exit 0;
+}
 
 my $buff;
 
@@ -31,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;
@@ -87,14 +93,22 @@ while(1) {
                }
        } elsif ( $buff =~ m/% Unrecognized command/ ) {
                exit 1;
-       } elsif ( $buff =~ s{More: <space>,  Quit: q.*One line: <return> }{} ) {
+       } elsif ( $buff =~ s{More: <space>,  Quit: q.*One line: <return>\s*}{} ) {
                send_pty " ";
-       } elsif ( $buff =~ s{\e\[0m\r\s+\r}{} ) {
+       } elsif ( $buff =~ s{\Q--More-- or (q)uit\E}{} ) {
+               send_pty " ";
+       } elsif ( $buff =~ s{\e\[0m\s*\r\s+\r}{} ) {
+               # nop
+       } elsif ( $buff =~ m/^[\r\n]+[\w\-]+>$/ ) {
+               send_pty "enable\n";
        }
 }
 
 __DATA__
+show system
 show arp
 show vlan
 show running-config
-show bridge address-table
+show bridge address
+show interfaces status
+