Skip to main content

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).

#!/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