expect 交互式传输文件(foreach)
一、脚本
#!/usr/bin/expect set RemoteDir /usr/local/Mail set LocalDIR /home/edm_report/doc set Date [exec date "+%Y%m%d"] #scp title and mail file from 10.91.20.180 to localhost foreach filename { mail title.txt } { set timeout 20 spawn scp root@10.91.20.180:${RemoteDir}/${filename} ${LocalDIR}/${filename}${Date} expect { "no)?" {send "yes\r";exp_continue} } expect { "password:" {send "123456\r"} } expect eof }
二、总结:
可以定义变量日期。
使用foreach 循环。
原文地址:http://hunkz.blog.51cto.com/6157447/1794879