6 # example usage as pipe:
7 # ./ips | sed 's/^/ping /' | NO_LOG=1 ./dell-switch.pl sw-dpc
10 use Data::Dump qw(dump);
11 use Time::HiRes qw(sleep);
15 our $debug = $ENV{DEBUG} || 0;
20 #$Net::OpenSSH::debug = ~0;
22 my $hostname = shift @ARGV || die "usage: $0 hostname command[ command ...]\n";
25 if ( ! @commands && ! -t STDIN && -p STDIN ) { # we are being piped into
29 } elsif ( ! @commands ) {
30 # push @commands, "/export verbose file=$hostname.rsc";
31 push @commands, "/export file=$hostname.rsc";
32 push @commands, "/tool fetch address=10.20.0.216 mode=ftp src-path=$hostname.rsc dst-path=upload/$hostname.rsc upload=yes";
33 my $file = "/srv/ftp/upload/$hostname.rsc";
35 system "sudo rm -vf $file";
39 $login .= '+c'; # Mikrotik console without colors
41 warn "\n## ssh $login\@$hostname\n";
42 my $ssh = Net::OpenSSH->new($hostname, user => $login, passwd => $passwd,
43 ssh_cmd => '/usr/bin/ssh1', # apt-get install openssh-client-ssh1
45 -o => "StrictHostKeyChecking=no",
46 -F => '/home/dpavlin/dell-switch/ssh1-config'
49 -o => "StrictHostKeyChecking=no",
50 -F => '/home/dpavlin/dell-switch/ssh1-config'
55 my @commands_while = ( @commands );
57 while ( my $command = shift @commands_while ) {
59 print "## $command\n";
60 my ($out, $err) = $ssh->capture2($command);
62 die "remote find command failed: " . $ssh->error;
64 warn "# out = ",dump($out);
70 system "cp -v /srv/ftp/upload/$hostname.rsc mikrotik/";