Posted to tcl by meissa at Tue Oct 29 20:37:33 GMT 2024view raw
- #!/usr/bin/expect
- set cmd [lrange $argv 2 end]
- set timeout [lindex $argv 0]
- set password [index $argv 1]
- set timeout $timeout
- eval spawn -noecho $cmd
- log_user 0
- expect {
- -nocase -re "^.*password.*: " {
- send "$password\r"
- #log_user 1
- exp_continue
- }
- timeout { exit 1 }
- eof
- }
- catch wait result
- #puts [string range "$expect_out(buffer)" 2 end-2]
- set out $expect_out(buffer)
- if {[string range $out 0 1] == "\r\n"} {
- set out [string range $out 2 end]
- }
- if {[string range $out end-1 end] == "\r\n"} {
- set out [string range $out 0 end-2]
- }
- puts $out
- exit [lindex $result 3]
Add a comment