Posted to tcl by Texan at Thu Jan 31 21:12:25 GMT 2019view raw

  1. #!/usr/bin/expect
  2.  
  3. set host [lindex $argv 0]
  4. set klishprompt "$host>"
  5. set shellprompt "myuser]"
  6. set component [lindex $argv 1]
  7.  
  8. spawn ssh -oUserKnownHostsFile=/dev/null myuser@$host
  9.  
  10. set timeout 2
  11. expect {
  12. timeout {
  13. puts "Connection timed out"
  14. exit 1
  15. }
  16.  
  17. "yes/no" {
  18. send "yes\r"
  19. exp_continue
  20. }
  21.  
  22. "assword:" {
  23. send -- "hammerhead\r"
  24. exp_continue
  25. }
  26.  
  27. "password for myuser:" {
  28. send -- "mypass\r"
  29. exp_continue
  30. }
  31.  
  32. "$klishprompt" {
  33. send "shell\r"
  34. exp_continue
  35. }
  36.  
  37. "$shellprompt" {
  38. exec "mv -f /some/directory/$component /some/other/dir"
  39. exec "exit\r"
  40. exec "exit\r"
  41. exit 0
  42. }
  43. }