Posted to tcl by meissa at Tue Oct 29 19:50:58 GMT 2024view raw

  1. #!/usr/bin/expect
  2.  
  3. set cmd [lrange $argv 2 end]
  4. set timeout [lindex $argv 0]
  5. set password [index $argv 1]
  6.  
  7. set timeout $timeout
  8.  
  9. eval spawn -noecho $cmd
  10. log_user 0
  11. expect {
  12. -nocase -re "^.*password.*: " {
  13. send "$password\r"
  14. log_user 1
  15. exp_continue
  16. }
  17. timeout { exit 1 }
  18. eof
  19. }
  20. catch wait result
  21. puts "result: '$expect_out(buffer)'."
  22. exit [lindex $result 3]
  23.  
  24.  
  25. $ expect ./pw_expect.tcl -1 <p/w> ssh ... <host> <cmd> 0</dev/null
  26.  
  27. <cmd output>
  28. result: '
  29. <cmd output
  30. '.
  31. $