Search code examples
bashsshexpectcisco

Bash script - second login after logging in with SSH


After you succesfuly SSH into IP Cisco phone, another login prompt (snoopyplus login:) and after that Password:appears. I want to create a script that spawns ssh, connects to the device, logs in again in the second login prompt and then does something. So far I tried something like that:

 $!/usr/bin/expect -f
 spawn ssh user@ip
 expect "assword:"
 send "pw"
 expect "snoopyplus login:"
 send "user2"
 expect "Password:"
 send "pw2"

Script connects with SSH and ends up on the snoopyplus login:I tried to expect different words (login, ogin, snoopy..) instead of the "snoopyplus login" but it never worked. I tested it with sshpass but it ends up in the same place. I don't want to use SSH key and I don't mind having password visible. Is there a way to do it? Thank you


Solution

  • I would put a sleep interval after you send password the first time, this will allow expect to have time. Most of my expect use is in python with pexpect using sendline which appends a carriage return, it looks like you would need to add this manually in Tcl. Also with my experience between multiple different mfgs and OS's, expecting the end of your prompt ('>', "#", "%", ":") mitigates some issues.