Score:0

Cron not running a command properly

de flag

I have HP ProLiant Utilities installed on my Ubuntu Server. Using the following shell command I am able to save the output of the RAID status to a log file:

sudo ssacli ctrl all show config > /var/logs/raid.log

I then tried to create a cron job so that on a daily basis the log file is overwritten with the status. My cron job looks like this:

30 15 * * * ssacli ctrl all show config > /var/logs/raid.log #Log RAID Status

This cron job is for root user.

The problem is that, if I go to Webmin and run this cron job by pressing "Save & Run Now" the log file is created. But if I let the cron job run at it's designated time, the log file is created but is blank.

I think it might have something to do with the fact that I need to run the ssacli in sudo mode

Can anyone help please?

Thanks

uz flag
Jos
First rule of `cron`: always provide full paths. In this case, you may need to write `/usr/bin/ssacli` instead of `ssacli`. The executable `ssacli` may be found somewhere else than in `/usr/bin/`; you can find out where with `which ssacli`.
John Roberts avatar
de flag
Awesome. thanks. that was it. I just had to put full path to ssacli which was /usr/sbin/ssacli
Score:1
it flag

Jobs run through cron aren't run in the same runtime environment that you have on your desktop. None of your PATH changes, or other environment variable settings from ~/.bashrc are automatically propagated to your cron job. For example, there's no $DISPLAY, so GUI programs need special treatment (read man xhost).

One can set environment variables for all one's cron jobs in the crontab file Read man 5 crontab.

Look at the results of echo "=== id ===";id;echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias in each of your environments.

Since the command part of the crontab line is, by default, interpreted by /bin/sh, which has a simpler syntax than /bin/bash, I recommend having command be a call to a bash script (executable, mounted, starts with #!/bin/bash) which sets up the environment, then calls the desired program.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.