Requisito previo: el comando de espera se ha instalado en el servidor Linux actual
En el servidor actual de Linux, ejecute el comando sudo -u testid esperar /home/test/expect.sh 20.181.103 201.811 para llamar /home/testid/remote_test.sh en el servidor remoto (192.168.1.1).
#!/usr/bin/expect
set timeout -1
set USER "testid"
set PWD "testpwd"
set HOST "192.168.1.1"
set YMD [lindex $argv 0]
set YM [lindex $argv 1]
spawn ssh $USER@$HOST
expect {
"*yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$PWD\r"}
}
expect "$*" {
send "/home/testid/remote_test.sh \r"
}
expect {
"fail" {
send "exit \r"
exit 1
}
"success" {
send "exit \r"
exit 0
}
"$*" {
send "exit \r"
exit 2
}
}