Expect脚本下不工作的crontab [英] Expect script does not work under crontab
问题描述
我有一个 expect脚本,我需要我的管理节点上运行,每3分钟收集TX / RX使用命令连接到DCX博科SAN交换机每个端口值 #portperfshow#
每一次我尝试使用的crontab 执行脚本,每3分钟,该脚本不起作用!
我希望脚本启动与#的/ usr / bin中/期望-f
和我使用的cron下以下语法调用脚本:
3 * * * *的/ usr / bin中/期望-f /root/portsperfDCX1/collect-all.exp sanswitchhostname
然而,当我执行脚本(未在cron下),它按预期工作:
根#./collect-all.exp sanswitchhostname
作品就好。
请请谁能帮!谢谢你。
脚本收集-all.exp是:
#!的/ usr / bin中/期望-f#时间和日期
集天[时间戳-format%D%M%Y]
设定的时间[时间戳-format%H%M]#logging
设置LogDir1/ FPerf / PortsLogs
等超时5
设置IPADDR [lrange $ ARGV 0 0]
集PASSWXXXXXXX
如果{$ IPADDR ==} {
把用法:其中,script.exp>< IP地址> \\ n
1号出口
}
产卵SSH管理@ $ IPADDR
预计-re密码
发送$ PASSW \\ R预计-re管理员 LOG_FILE$ LogDir1 / $日portsperfshow- $时间
发送portperfshow -tx -rx -t 10 \\ R
预计超时\\ n
发送\\ 003
LOG_FILE 送 - 退出\\ R
关
我有同样的问题,但我的脚本是用
结束 互动
最后,我把它用这两条线取代它的工作:
预计EOF
出口
I have an expect script which I need to run every 3 mins on my management node to collect tx/rx values for each port attached to DCX Brocade SAN Switch using the command #portperfshow#
Each time I try to use crontab to execute the script every 3 mins, the script does not work!
My expect script starts with #!/usr/bin/expect -f
and I am calling the script using the following syntax under cron:
3 * * * * /usr/bin/expect -f /root/portsperfDCX1/collect-all.exp sanswitchhostname
However, when I execute the script (not under cron) it works as expected:
root# ./collect-all.exp sanswitchhostname
works just fine.
Please Please can someone help! Thanks.
The script collect-all.exp is:
#!/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
I had the same issue, except that my script was ending with
interact
Finally I got it working by replacing it with these two lines:
expect eof
exit
这篇关于Expect脚本下不工作的crontab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!