Posted to tcl by meissa at Tue Oct 29 19:35:32 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
- exit [lindex $result 3]
- $ var="$(expect ./pw_expect.tcl -1 <p/w> ssh ... <host> <cmd> 0</dev/null)"
- $ echo "$var"
- password:
- <cmd output>
- $