我有一个 期待脚本 我需要在管理节点上每 3 分钟运行一次,以使用命令 #portperfshow#
为连接到 DCX Brocade SAN 交换机的每个端口收集 tx/rx 值。
每次我尝试使用 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
关于automation - Expect 脚本在 crontab 下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7494115/