comprehensive expect examples

Can anybody point me to some useful, comprehensive expect examples? I am trying to build a bash script with some telnet interactions.

Appreciate any help.

Persio

Hi,

I wrote an expect script to log in to all cisco switches on our network which uses telnet. The main problem for me was that the usernames and passwords weren't consistent across all switches. My code looked like this ...

log_file -noappend ./CDP_LOGS/$ip_addr.log
# This spawns the telnet program and connects it to the IP address
 spawn telnet $ip_addr
 #The script expects Password or Username or times out if no response is seen
 expect {
   "Password: "  {login1a $ip_addr}
   "Username: "  {login2a $ip_addr}
   timeout       {abort $ip_addr 1}
 }
 log_file

If "Password: " or "Username: " are identified, the appropriate proc is called (either login1a or login2a respectively). Once logged in successfully, you can continue to send commands using this construct:

send "command"
 while {1} {
   expect "some output 1" {
     do stuff
   } "some output 2" {
     do stuff
     break
   } "some output 3" {
     do stuff
     break
   }
 }

This expects multiple things and reacts accordingly.

All my output was logged to a file which I used for post-processing.

Hope this is helpful.

Gavin