Posted to tcl by miessa at Tue Oct 29 19:21:09 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
- expect {
- -nocase -re "^.*password.*: " {
- send "$password\r"
- 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>
- $
Add a comment