I have the next problem: When I run my script from the unix shell (CentOS 6.7), my script runs without any error messages and works fine.
The problem appears when I try to execute it from a cron job at a specific time.
This is the script:
#! /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
The Cron error says:
/root/reload-cisco.sh: line 4: unixcat: command not found
Why happens this?
Thanks in advance.