7 use Data::Dump qw(dump);
8 use Time::HiRes qw(sleep);
12 our $debug = $ENV{DEBUG} || 0;
16 #$Net::OpenSSH::debug = ~0;
18 my $ip = shift @ARGV || die "usage: $0 IP command[ command ...]\n";
20 @commands = <DATA> unless @commands;
23 my $ssh = Net::OpenSSH->new($ip, user => $login, passwd => $passwd);
24 my ($pty ,$pid) = $ssh->open2pty();
26 warn "ERROR: can't connect to $ip, skipping";
34 sleep 0.1; # we really need to wait for slow PowerConnect 5324
35 foreach (split //, $string) {
36 print STDERR "[$_]" if $debug;
41 sysread $pty, my $echo, 1;
47 mkdir 'log' unless -d 'log';
52 my ($ip, $hostname, $command, $buff) = @_;
54 return unless $command;
56 my $file = "${ip}_${hostname}_${command}.log";
57 open my $log, '>', $file;
58 $buff =~ s/\r//gs; # strip CR, leave LF only
61 system 'git', 'add', $file;
62 system 'git', 'commit', '-m', "$ip $hostname", $file;
70 my $read = sysread($pty, $data, 1);
73 if ( $buff =~ m/User Name:/ ) {
76 } elsif ( $buff =~ m/Password:/ ) {
79 } elsif ( $buff =~ m/([\w\-]+)>$/ ) {
81 } elsif ( $buff =~ m/([\w\-]+)#$/ ) {
84 save_log $ip, $hostname, $command, $buff;
87 if ( $command = shift @commands ) {
88 $command =~ s/[\n\r]+$//;
89 send_pty "$command\n";
96 } elsif ( $buff =~ m/% Unrecognized command/ ) {
98 } elsif ( $buff =~ s{More: <space>, Quit: q.*One line: <return> }{} ) {
101 } elsif ( $buff =~ s{\Q--More-- or (q)uit\E}{} ) {
104 } elsif ( $buff =~ s{\e\[0m\r\s+\r}{} ) {
112 show bridge address-table