【问题标题】:Cron shows me a script errorCron 显示脚本错误
【发布时间】:2016-05-12 22:09:05
【问题描述】:

我有下一个问题: 当我从 unix shell (CentOS 6.7) 运行我的脚本时,我的脚本运行没有任何错误消息并且工作正常。

当我尝试在特定时间从 cron 作业执行时出现问题。

这是脚本:

#! /bin/bash

#Retrieve the status of the workstations into a file thanks to Nagios
echo -e "GET hosts\nColumns: address state\nFilter: address != 127.0.0.1" | unixcat /usr/local/nagios/var/rw/live > workstation_state.txt

#Read that file line by line
while read line
do
    IP=$(echo $line | cut -d ';' -f 1)
        STATE=$(echo $line | cut -d ';' -f 2)

        # Check the state of the workstation. If is 0, it means that is up, else is down
        # Only if the workstation is up we are going to connect through SSH and reload the device
        if [ $STATE -eq 0 ]
        then
                (echo "reload in 1"; echo "y"; echo "exit";) | sshpass -p 'K910p.,lo-16' ssh -A lab@$IP
        fi
done < workstation_state.txt

Cron 错误说:

/root/reload-cisco.sh: line 4: unixcat: command not found

为什么会这样?

提前致谢。

【问题讨论】:

  • 你在使用/full/path/to/unixcat的时候还会遇到同样的错误吗?
  • 不,如果我将完整路径放到 unixcat 中,脚本可以使用 cron 作业正常工作。
  • 那解决了您的问题吗?我可以发布答案,以便将来可以帮助其他人。
  • 非常感谢您的帮助。

标签: cron centos


【解决方案1】:

运行which unixcat 以查找命令的绝对路径,并在脚本中使用它。在 crons 中使用命令的完整路径,因为它可能会擦除您的 $PATH 变量,这可能是您所有二进制文件和可执行文件所在的位置 - 所以当 cron 执行脚本时,它不知道在哪里寻找 @987654322 @ 命令。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 2014-12-01
    • 2020-02-06
    • 1970-01-01
    相关资源
    最近更新 更多