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 [email protected]:${RemoteDir}/${filename} ${LocalDIR}/${filename}${Date} expect { "no)?" {send "yes\r";exp_continue} } expect { "password:" {send "123456\r"} } expect eof }
二、总结:
- 可以定义变量日期。
- 使用foreach 循环。
时间: 2024-10-11 11:30:51