Ipmitool script does not work as cron job

Running ipmitool in shell to startup backup server works without issue.
But it does not work as a cron job. Tried both running the command and wrap in a script in cron do not work. Job is running as root. there are no job logs to check…

Here is what I have experienced with cronjob failures:

  1. PATH to command is not working, “command” verses “/usr/sbin/command”
  2. Permissions, needs to run as user “root”. You have this one covered
  3. Other environment variables that the command needs are not part of the Cronjob’s running instance. You would need to manually set them in a script before running “command”.
  4. The "command"s parameters are not correct. You seem to have this one handled as well.

In order to trouble shoot a Cronjob, you can use “echo” statements at various points to show where it got to:

#!/bin/bash
#
touch                                      /root/my_cron,out
echo "starting cronjob"                  >>/root/my_cron,out
date                                     >>/root/my_cron,out
/PATH/TO/SETUP SETUP_PARAMETERS     2>&1 >>/root/my_cron,out
echo "Setup complete"                    >>/root/my_cron,out
/PATH/TO/COMMAND COMMAND_PARAMETERS 2>&1 >>/root/my_cron,out
echo "Command complete"                  >>/root/my_cron,out
exit 0

You can then examine the log file and get a clue on what failed. Whence you are happy, you can either remove the logging statements. Or leave them in, but change the “touch” command to something that zeros out the log file at the beginning of the script. So you would have only the most current instance logged.

Here is something you can use to replace “touch”, to restart the log file:

cat /dev/null >/root/my_cron,out
1 Like

got it working! thanks! I was missing a “/” on the first line of the script.

1 Like