21 lines
423 B
Plaintext
21 lines
423 B
Plaintext
|
#!/usr/bin/expect -f
|
||
|
# usage:
|
||
|
# ./ssh-sudo.exp username password hostname command
|
||
|
set username [lrange $argv 0 0]
|
||
|
set password [lrange $argv 1 1]
|
||
|
set hostname [lrange $argv 2 2]
|
||
|
set command [lrange $argv 3 3]
|
||
|
set timeout 5
|
||
|
spawn ssh -t $username@$hostname sudo $command
|
||
|
expect "*yes/no*" {
|
||
|
send -- "yes\r"
|
||
|
}
|
||
|
expect "*assword*" {
|
||
|
send -- "$password\r"
|
||
|
}
|
||
|
expect "*assword*" {
|
||
|
send -- "$password\r"
|
||
|
}
|
||
|
expect eof
|
||
|
|