Bash:- expect远程执行shell脚本交互

脚本执行时,需要输入交互"y",用expect可以实现交互输入过程;

#!/usr/bin/expect -f

set ipaddr [lindex $argv 0]
set port "23000"

spawn -noecho ssh -p $port root@$ipaddr

expect {
    -re "\]# " {
        send "bash /data/app/lhzs/public/script/checksvr.sh\n"

        expect {

            -re "\]: " {
                send "y\n"
                exp_continue
            }

            -re "\]# " {
                send "exit\n"
            }

        }

    }
}

expect eof
exit

 

posted @ 2017-03-11 15:26  ithandonglin  阅读(1961)  评论(3编辑  收藏  举报