Posted to tcl by Texan at Tue May 23 14:49:10 GMT 2017view raw

  1. #!/usr/bin/expect
  2.  
  3. set passwdPrompt "password"
  4. set loginUser "user"
  5. set loginPassword "pass"
  6. set address "addr"
  7.  
  8. spawn ssh -l $loginUser $address
  9. expect "$passwdPrompt" {
  10. send "$loginPassword\r"
  11. }
  12.  
  13. proc login_from_protected_shell { } {
  14. set timeout 2
  15. expect {
  16. timeout {
  17. puts "Function 1 timed out"
  18. return 1
  19. }
  20.  
  21. "<protected shell>" {
  22. send -- "shell\r"
  23. exp_continue
  24. }
  25.  
  26. "password" {
  27. send "<somepass>\r"
  28. exp_continue
  29. }
  30.  
  31. "<shell>" {
  32. # nothing to do, success!
  33. return 0
  34. }
  35. }
  36. }
  37.  
  38. proc other_things_to_do { } {
  39. expect "<shell>" {
  40. send "cd /home/mydir\r"
  41. }
  42.  
  43. expect "<shell>" {
  44. send "touch poop.pee\r"
  45. return 0
  46. }
  47. }
  48.  
  49. # drop to a shell
  50. login_simple
  51.  
  52. # download the base
  53. other_things_to_do