Running executable from Crontab

1

I have a file called Exim_queue_size in the root directory. It contains one line:

exim -bpc | mail -s'Exim_queue_size' bert@example.com

It has had its permissions set with chmod +x , and is thus executable.

If I run ./Exim_queue_size, it works perfectly and mails the queue size count.

If I load to run in the crontab, with the line

0 3,6,9,12,15,18,21,0 * * * /root/Exim_queue_size

I receive a correctly titled e-mail with no count attached.

Any ideas please?

Brian Ellse

Posted 2015-05-11T19:49:28.400

Reputation: 11

Please provide the misbehaving entry exactly as stated in your crontab. In addition, please provide any configuration/environment lines, if present, from your crontab. I suspect environment difference. – Jarmund – 2015-05-11T20:13:09.530

@Jarmund My cron entry is and i see no environment/config line in the crontab file. code

0 0,3,6,9,12,15,18,21 * * * /root/Exim_queue_size – Brian Ellse – 2015-05-12T00:58:32.280

Answers

3

Just a guess, but exim might be in a location that is not in your path by default. And if exim is not found a blank message is what your script will produce.

When you login, you have a variety of files like .bashrc that add directories to your path. But these config files are not all sourced when cron runs. Try this on the command line...

$ which exim
/usr/local/somepath/exim

Then use the resulting full path in your script...

/usr/local/somepath/exim -bpc | mail -s'Exim_queue_size' bert@example.com

Bill Heller

Posted 2015-05-11T19:49:28.400

Reputation: 981

Thanks Bill, however the crontab calls the executable in the root, and the executable works perfectly when run as ./Exim_queue_size from its location in the root directory. So still looking. FWIW exim is at /usr/bin/exim :-) – Brian Ellse – 2015-05-12T00:09:07.697

Well it's not at all inconceivable that it would run perfectly from a login shell and then fail from cron. But yeah, it's unlikely that cron does not have /usr/bin in its path. Sure, sorry that didn't help. – Bill Heller – 2015-05-12T00:36:22.470

You might be able to see what is going on by redirecting stderr and stdout to a temp file from cron... "exim -bpc >>/tmp/crontest 2>&1" I suspect it has to do be something going wrong with that part of the command since you are getting an email. After that runs you can cat /tmp/crontest and see if there is anything there. – Bill Heller – 2015-05-12T00:38:17.943

0

I edited executable Exim_queue_size to read

/usr/bin/exim -bpc | mail -s'Exim_queue_size' bert@example.com

as suggested by Bill Heller, and on the cron run at 3am, the correct mail was received. Problem solved. Thank you.

Brian Ellse

Posted 2015-05-11T19:49:28.400

Reputation: 11