下述代码解决两个自动化过程:
1> spawn scp -r 指定文件 xxxxs@xx.xx.xx.xx:目标文件夹地址
指定文件:不能像 ./* 加载全部数据(spawn 命令支持,单scp可以)
2> 免密登录(在无法使用ssh情况)
if [ `ls 待传送文件夹 | wc | awk '{print $1}'` -gt 0 ]
then
for f in `ls 待传送文件夹`
do
expect -c "
spawn scp -r 指定文件 xxxx@xx.xx.xx.xx:目标文件夹地址
expect {
\"*assword\" {set timeout 300; send \"密码\r\"}
}
expect eof"
done
else
echo "没有文件"
fi