automation - Expect 脚本在 crontab 下不起作用

标签 automation cron crontab expect

我有一个 期待脚本 我需要在管理节点上每 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/

相关文章:

java - 此错误 "Unable to create a XML-RPC client"的解决方案是什么?

python - 如何在 GNU/Linux 中使用 python 自动化 GUI 应用程序的操作?

html - 如何在 Groovy/Geb 中一个一个地点击复选框?

ruby - 在 RVM env 的 Ruby cron 作业中找不到 Gem

php - 数据库设计

php - 如何从 php 脚本设置 cron 作业?

php cron作业没有运行

javascript - 是否可以控制 typed.js 插件何时开始和停止输入文本?

node.js - 谷歌云平台 : Running several hours scraping script

php - 如何在 crontab 中运行带参数的 php url