0

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.

nobody
  • 19,814
  • 17
  • 56
  • 77
Jesfer
  • 31
  • 1
  • 6

1 Answers1

1

Run which unixcat to find the absolute path of the command, and use that in the script instead. Use the full path for commands in crons because it might wipe your $PATH variable, which is presumably where all your binaries and executables are located -- so when the cron executes the script, it doesn't know where to look for the unixcat command.

drewyupdrew
  • 1,549
  • 1
  • 11
  • 16