added ability to enter configure mode and confirm save config
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 23 Aug 2017 12:39:49 +0000 (14:39 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 23 Aug 2017 12:39:49 +0000 (14:39 +0200)
README [new file with mode: 0644]
dell-switch.pl

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..afb71eb
--- /dev/null
+++ b/README
@@ -0,0 +1,14 @@
+./ips | xargs -i ./dell-switch.pl {} "show bridge address"
+
+./ips | xargs -i ./dell-switch.pl {} "show interfaces status"
+
+./ips | xargs -i ./dell-switch.pl {} "show running-config"
+
+This will save all commands executed to git repository under log/
+
+However, somethimes you just need to execute few commands but don't want
+log output (if configuring switches in batch, for example). You can do
+that by setting NO_LOG enviroment variable like this:
+
+grep -A 1 sw-lib /etc/munin/munin.conf | grep 10.20 | awk '{ print $2 }' \
+| NO_LOG=1 xargs -i ./dell-switch.pl 'snmp-server community public-or-not ro view Default' 'exit' 'copy running-config startup-config'
index 65cc0be..9b0c3f7 100755 (executable)
@@ -53,6 +53,7 @@ sub save_log {
        my ($ip, $hostname, $command, $buff) = @_;
 
        return unless $command;
+       return if $ENV{NO_LOG};
        
        my $file = "${ip}_${hostname}_${command}.log";
        open my $log, '>', $file;
@@ -78,7 +79,7 @@ while() {
        } elsif ( $buff =~ m/Password:/ ) {
                send_pty "$passwd\n";
                $buff = '';
-       } elsif ( $buff =~ m/([\w\-]+)#$/ ) {
+       } elsif ( $buff =~ m/([\w\-\(\)]+)#$/ ) {
                my $hostname = $1;
                if ( $buff ) {
                        save_log $ip, $hostname, $command, $buff;
@@ -103,6 +104,9 @@ while() {
                # nop
        } elsif ( $buff =~ m/^[\r\n]+[\w\-]+>$/ ) {
                send_pty "enable\n";
+       } elsif ( $buff =~ m{\QOverwrite file [startup-config] ?[Yes/press any key for no]....\E} ) {
+               send_pty "y";
+               $buff = '';
        }
 }