Posted to tcl by meissa at Tue Oct 29 20:37:33 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 [string range "$expect_out(buffer)" 2 end-2]
  22. set out $expect_out(buffer)
  23. if {[string range $out 0 1] == "\r\n"} {
  24. set out [string range $out 2 end]
  25. }
  26. if {[string range $out end-1 end] == "\r\n"} {
  27. set out [string range $out 0 end-2]
  28. }
  29. puts $out
  30. exit [lindex $result 3]

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