#!/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 "
expect "*assword" { send "$password "}
}
"*assword"
{
send "$password "
}
}
expect "100%"
expect eof
EOF