Posted to tcl by miessa at Tue Oct 29 19:21:09 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. expect {
  11. -nocase -re "^.*password.*: " {
  12. send "$password\r"
  13. exp_continue
  14. }
  15. timeout { exit 1 }
  16. eof
  17. }
  18. catch wait result
  19. exit [lindex $result 3]
  20.  
  21.  
  22. $ var="$(expect ./pw_expect.tcl -1 <p/w> ssh ... <host> <cmd> 0</dev/null)"
  23. $ echo "$var"
  24. password:
  25. <cmd output>
  26. $
  27.  

Add a comment

Please note that this site uses the meta tags nofollow,noindex for all pages that contain comments.
Items are closed for new comments after 1 week