Expect 脚本在 crontab 下不起作用 [英] Expect script does not work under crontab

查看:28
本文介绍了Expect 脚本在 crontab 下不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 expect 脚本,我需要在我的管理节点上每 3 分钟运行一次,以使用命令 #portperfshow 为连接到 DCX Brocade SAN 交换机的每个端口收集 tx/rx 值#

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#

每次我尝试使用 crontab 每 3 分钟执行一次脚本时,该脚本不起作用!

Each time I try to use crontab to execute the script every 3 mins, the script does not work!

我的期望脚本以 #!/usr/bin/expect -f 开头,我在 cron 下使用以下语法调用脚本:

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 

但是,当我执行脚本(不在 cron 下)时,它按预期工作:

However, when I execute the script (not under cron) it works as expected:

root# ./collect-all.exp sanswitchhostname

效果很好.

请有人帮忙!谢谢.

脚本 collect-all.exp 是:

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>
"
        exit 1
}


spawn ssh admin@$ipaddr
expect -re "password"
send "$passw
"

expect -re "admin"

                log_file "$LogDir1/$day-portsperfshow-$time"
                send "portperfshow -tx -rx -t 10
"
                expect timeout "
"
                send 03
                log_file

                send -- "exit
"
                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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆