#!/bin/expect # log in to boxes automatically, best as a bash alias # http://wiki.tcl.tk set hosts("se400s") [list "ac1.hrbg.pa" "ac1.mftw.pa"] set hosts("sms1800s") [list "ac1.wash.dc"] set hosts("asx200s") [list "atm1.hrbg.pa" "atm1.mftw.pa" "atm1.wash.dc" ] set hosts("cat2ks") [list "sw1.hrbg.pa" "sw1.mftw.pa" "sw1.wash.dc" ] set prompts("se400s") [list "ogin" "word" ">\$" "word" "#\$" ] set prompts("sms1800s") [list "ame" "word" ">\$" "word" "#\$" ] set prompts("asx200s") [list "ogin" "word" "> \$" ] set prompts("cat2ks") [list "word" ">\$" "word" "#\$" ] # password file should have the responses to the prompts above for each type, like: # set passwds("se400s") [list "my_name" "my_password" "enable" "enable_password" set passwdfile "/cygdrive/u/etc/passwd.tcl" set timeout 30 proc die { warning } { puts $warning exit } foreach {host cmd} $argv break if { [file isfile $passwdfile] } { source $passwdfile } else { die "no password file found at: '$passwdfile' exiting..." } set host_type "" foreach type [array names hosts] { foreach name $hosts($type) { if {$name == $host } { set host_type $type } } } if { $host_type == "" } { die "host not found in database, exiting..." } exp_spawn telnet $host foreach prompt $prompts($host_type) response $passwds($host_type) { expect -regexp $prompt exp_send "$response\r" } expect -regexp [lindex $prompts($host_type) "end" ] if { $cmd == "" } { exp_interact exit } exp_send "$cmd\r" expect { -regexp [lindex $prompts($host_type) "end" ] { exp_send "exit\r" } "for more" { exp_send "\r" exp_continue } } # tidy up nicely catch {expect eof} puts "" exit