先看上一文章中expect里的脚本:
[root@mail root]# more getdata.sh
#!/usr/bin/expect
set password 123456
spawn /usr/bin/scp /web/backup/
expect "password"
send "$password"
send "\n"
interact
这时你会发现红色字体为日期参数yyyy-mm-dd.
如何用shell里的date命令进行引用呢.实在没办法,对角本进行如下处理.
[root@mail tmp]# more getdata.sh
#!/usr/bin/expect
set password 123456
set DATE [lindex $argv 0]
spawn /usr/bin/scp
/web/backup/
expect "password"
send "$password"
send "\n"
interact
[root@mail tmp]# more scpdata.sh
#!/bin/sh
DATE=`/bin/date +%Y%m%d`
timestamp=`date +%Y-%m-%d`
/tmp/getdata.sh $timestamp
2010-12-14再次查看CU,有高人给出这样的脚本.很给力.
set password 123456
set date [exec date "+%Y-%m-%d"]
spawn /usr/bin/scp ://backup/test-file-$date /test/backup/
expect "assword:"
send -- "$password\r"
expect "assword:"
send -- "$password\r"
expect eof