Metainformationen zur Seite
Autologin auf Cisco-Switch mittels expect
Dieses Script ermöglicht einen automatischen Login auf Cisco-Switche inkl. automatischem „enable“ (sofern die beiden Kennwörter gleich sind).
neue bessere Version von Markus Frosch, ohne Umwege über Bash ;)
#!/usr/bin/expect -f ####################################### ## Update Router Config ####################################### set host [lindex $argv 0] set pw XXXX trap exit {SIGINT SIGTERM} spawn telnet $host expect { "Username: " { send "root\r" exp_continue } "Password: " { send "$pw\r" } timeout { send_user "\n\ntimeout...\n" exit 1 } } expect { "% " { send_user "\n\nlogin failed.\n" exit 1 } ">" { send "enable\r" } } expect { "Password: " { send "$pw\r" } timeout { send_user "\n\ntimeout...\n" exit 1 } } expect { "% " { send_user "\n\nenable failed.\n" exit 1 } "#" { send_user "\nlogged in...\n" send "\n" } } interact
#!/bin/sh # Passwort PASS="passwort" PROGDIR=`dirname $0` rm -f $PROGDIR/login.expect touch $PROGDIR/login.expect chmod u+x $PROGDIR/login.expect cat << EOF > $PROGDIR/login.expect #!/usr/bin/expect spawn telnet $1 expect { "Password:" { send "$PASS\r" exp_continue } "Name:" { send "enable\r" exp_continue } "#" { interact } "% Bad passwords" { send_user "invalid password or account\n" exit } timeout { send_user "connection timed out\n" exit } eof { send_user "connection to $host failed: $expect_out(buffer)" exit } } EOF $PROGDIR/login.expect rm -f $PROGDIR/login.expect
Aufruf mit „cisco.sh catalyst1.mydomain.de“ oder via IP.
Diskussion