liunx使用expect 实现远程执行 脚本

#!/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


猜你喜欢

转载自blog.csdn.net/u012040869/article/details/80000441
今日推荐