+sub send_pty {
+ my $string = shift;
+ sleep 0.1; # we really need to wait for slow PowerConnect 5324
+ foreach (split //, $string) {
+ print STDERR "[$_]" if $debug;
+ syswrite $pty, $_;
+# $pty->flush;
+ sysread $pty, my $echo, 1;
+ print STDERR $echo;
+ $buff .= $echo;
+ }
+}
+
+mkdir 'log' unless -d 'log';
+
+chdir 'log';
+
+sub save_log {
+ my ($ip, $hostname, $command, $buff) = @_;
+
+ my $file = "${ip}_${hostname}_${command}.log";
+ open my $log, '>', $file;
+ $buff =~ s/\r//gs; # strip CR, leave LF only
+ print $log $buff;
+ if ( -e '.git' ) {
+ system 'git', 'add', $file;
+ system 'git', 'commit', '-m', "$ip $hostname", $file;
+ }
+}
+
+my $command;
+