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;
22 warn "\n## ssh $ip\n";
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\-]+)#$/ ) {
82 save_log $ip, $hostname, $command, $buff;
85 if ( $command = shift @commands ) {
86 $command =~ s/[\n\r]+$//;
87 send_pty "$command\n";
94 } elsif ( $buff =~ m/% Unrecognized command/ ) {
96 } elsif ( $buff =~ s{More: <space>, Quit: q.*One line: <return>\s*}{} ) {
98 } elsif ( $buff =~ s{\Q--More-- or (q)uit\E}{} ) {
100 } elsif ( $buff =~ s{\e\[0m\s*\r\s+\r}{} ) {
102 } elsif ( $buff =~ m/^[\r\n]+[\w\-]+>$/ ) {
113 show interfaces status