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 || '10.20.0.2';
20 @commands = <DATA> unless @commands;
23 my $ssh = Net::OpenSSH->new('auto@'.$ip);
24 my ($pty ,$pid) = $ssh->open2pty();
30 sleep 0.1; # we really need to wait for slow PowerConnect 5324
31 foreach (split //, $string) {
32 print STDERR "[$_]" if $debug;
35 sysread $pty, my $echo, 1;
41 mkdir 'log' unless -d 'log';
46 my ($ip, $hostname, $command, $buff) = @_;
48 return unless $command;
50 my $file = "${ip}_${hostname}_${command}.log";
51 open my $log, '>', $file;
52 $buff =~ s/\r//gs; # strip CR, leave LF only
55 system 'git', 'add', $file;
56 system 'git', 'commit', '-m', "$ip $hostname", $file;
64 my $read = sysread($pty, $data, 1);
67 if ( $buff =~ m/User Name:/ ) {
70 } elsif ( $buff =~ m/Password:/ ) {
73 } elsif ( $buff =~ m/([\w\-]+)#$/ ) {
76 save_log $ip, $hostname, $command, $buff;
79 if ( $command = shift @commands ) {
80 $command =~ s/[\n\r]+$//;
81 send_pty "$command\n";
88 } elsif ( $buff =~ m/% Unrecognized command/ ) {
90 } elsif ( $buff =~ s{More: <space>, Quit: q, One line: <return> }{} ) {
92 } elsif ( $buff =~ s{\e\[0m\r\s+\r}{} ) {
100 show bridge address-table