2012-07-29 71 views
2

我有期望的脚本来备份fortigate VDOM防火墙。Expect脚本不会将日期命令的bash替换扩展为发送

这很好,除了基于日期输出的动态文件名。

这是脚本:

<!-- language: expect --> 
#!/usr/bin/expect -f 

##!/bin/bash 
#DATE=$(date "+%Y.%m.%d") 
#echo $DATE 

set timeout 60 
spawn ssh [email protected] 
expect "password: $" 
set send_slow {1 0.05} 
send -s "pass\r" 
send_user "pass\r" 
send -s "config global\n" 
send -s "execute backup full-config tftp `date \"+%Y.%m.%d\"` ip.address\n" 
send -s "exit\n" 
interact 

该脚本的结果,是这样的: VDOM1#执行备份全配置TFTP date "+%Y.%m.%d" ip.address

谁能帮助吗?

回答

4

好吧,我得到了这个问题的答案在IRC(信用是Venks):

`不TCL特殊。 做的正确的方法是这样的:

send -s "execute backup full-config tftp [clock format [clock seconds] -format %Y.%m.%d] xxx.xxx.xxx.xxx\n" 

希望这可以帮助别人的未来。