0
我有下一個問題: 當我從unix shell(CentOS 6.7)運行我的腳本時,我的腳本運行時沒有任何錯誤消息,並且工作正常。Cron向我展示腳本錯誤
當我嘗試在特定時間從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 [email protected]$IP
fi
done < workstation_state.txt
cron的錯誤說:
/root/reload-cisco.sh: line 4: unixcat: command not found
爲什麼會發生呢?
在此先感謝。
使用'/ full/path/to/unixcat'時仍然會出現同樣的錯誤嗎? – drewyupdrew
不,如果我把unixcat的完整路徑使用cron作業,腳本可以正常工作。 – Jesfer
那麼解決了你的問題?我可以發佈答案,以便這篇文章可以幫助其他人。 – drewyupdrew