我有下一个问题: 当我从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
为什么会这样?
提前致谢。
答案 0 :(得分:1)
运行which unixcat
以查找命令的绝对路径,并在脚本中使用它。使用crons中命令的完整路径,因为它可能会擦除$ PATH变量,这可能是所有二进制文件和可执行文件所在的位置 - 所以当cron执行脚本时,它不知道在哪里查找{{ 1}}命令。