【发布时间】: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 作业正常工作。
-
那解决了您的问题吗?我可以发布答案,以便将来可以帮助其他人。
-
非常感谢您的帮助。