Posted to tcl by meissa at Tue Oct 29 19:50:58 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 "result: '$expect_out(buffer)'."
- exit [lindex $result 3]
- $ expect ./pw_expect.tcl -1 <p/w> ssh ... <host> <cmd> 0</dev/null
- <cmd output>
- result: '
- <cmd output
- '.
- $