The chances that you would be able to start SSH or Telnet session from an EEM applet were pretty slim, but the comment from melwong triggered my curiosity and I simply had to try it. After all, as the action cli command uses a VTY line (like a regular user session), you might be able to use the pattern option of the action cli command to write something similar to an expect script. This was my best shot at getting it done:
event manager
applet SSH
event none
action 0.9 cli command
"enable"
action 1.0 cli command "ssh -l ssUser
R2" pattern "word:"
action 1.1 cli command
"ssPassword" pattern "#"
action 2.0 cli
command "clear ip route *" pattern "#"
action 3.0
cli command "exit" pattern "#"My applet got past the SSH authentication (debugging on R2 confirmed that the SSH session was started) but could not send data through the session itself (it hung on the clear ip route command).
Note: This article is part of You've asked for it series.
Posted to Cisco IOS Hints and Tricks by IvanPepelnjak
©Copyright Ivan Pepelnjak