我有一个期望脚本,我需要在管理节点上每3分钟运行一次,以使用命令#portperfshow#来收集连接到DCX Brocade SAN交换机的每个端口的tx / rx值 每次尝试使用crontab每3分钟执行一次脚本,脚本不起作
每次尝试使用crontab每3分钟执行一次脚本,脚本不起作用!
我的预期脚本以#!/usr/bin/expect -f开头,我在cron下使用以下语法调用脚本:
3 * * * * /usr/bin/expect -f /root/portsperfDCX1/collect-all.exp sanswitchhostname
但是,当我执行脚本(不在cron下)它的工作原理:
root# ./collect-all.exp sanswitchhostname
工作很好
请有人帮忙!谢谢.
脚本collect-all.exp是:
#!/usr/bin/expect -f
#Time and Date
set day [timestamp -format %d%m%y]
set time [timestamp -format %H%M]
#logging
set LogDir1 "/FPerf/PortsLogs"
et timeout 5
set ipaddr [lrange $argv 0 0]
set passw "XXXXXXX"
if { $ipaddr == "" } {
puts "Usage: <script.exp> <ip address>\n"
exit 1
}
spawn ssh admin@$ipaddr
expect -re "password"
send "$passw\r"
expect -re "admin"
log_file "$LogDir1/$day-portsperfshow-$time"
send "portperfshow -tx -rx -t 10\r"
expect timeout "\n"
send \003
log_file
send -- "exit\r"
close
我有同样的问题,除了我的脚本结束
interact
最后我用这两行替换了它:
expect eof exit
