#!/bin/bash
#defined
expect /usr/local/resourceShell/exekill.sh xxxx xxxxx
sleep 2
expect /usr/local/resourceShell/exekill.sh xxx xxxxx
xx 代表向exekill.sh 传递的参数
exekill.sh 内容如下:
#!/usr/bin/expect -f
set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 120
spawn ssh root@$ipaddress
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "$passwd\r" }
}
expect "*from*"
#send "mkdir -p /usr/local/abc\r"
send "cd /usr/local/shell/resourceShell\r"
send "sh kill.sh\r"
send "exit\r"
expect eof