shell脚本嵌套expect脚本

#!/bin/sh

echo "helo"

password='xxxx' ###不能在下面的expect脚本段设置成 set password xxxx否则获取不到变量,单独的expect脚本变量可以这样设置

/usr/local/bin/expect <<EOF  ###安装的expect的路径一般为/usr/bin/expect

spawn scp -rp /home/test/  user@x.x.x.x:/home/test

expect {

    "(yes/no)?"  {

            send "yes\r"

            expect "*assword"  { send "$password\r"}

          }

    "*assword"  

          {

            send "$password\r"

          }

}

expect "100%"

expect eof

EOF

#http://blog.csdn.net/snow_114/article/details/53245466

posted @ 2016-12-14 16:47  FlyBack  阅读(6373)  评论(0编辑  收藏  举报