cron job not executing the binary in the time specified

0

I would like to check which is the environment being used if executing a cron job. I had it working before however it stopped at some point.

This is my cron job in the crontab file:

20 13 * * * /usr/bin/env >> /home/user/folder1/environment1.log

With this line, I am expecting to dump the environment variables to the environment1.log file.

Does anybody have a suggestion of what to check?

birdman

Posted 2019-06-21T13:35:17.753

Reputation: 1

Answers

1

EDIT: I have found a link on SO related to this. It is suggested to add 2>&1 to the end like:

* * * * * myjob.sh >> /var/log/myjob.log 2>&1

to correctly handle the redirection of the output. Some more information on the '2>&1' here.


A few things to check:

  • Does the user who is running the job have access to write to that location?
  • Can you run the command in the command line, and do you get the correct output?
  • Can you write the output to /tmp/some_filename.log?
  • The line you have implies the job will run at 13:20. Is this the time you were expecting?

Randomhero

Posted 2019-06-21T13:35:17.753

Reputation: 804

yes to all the questions – birdman – 2019-06-21T13:51:44.630

0

You can check the cron log to see if the event fired or not. On my centos unix, the path is:

/var/log/cron

I also have it configured so that the log rotate keeps around 30 days of logs, so I can check if something goes wrong.

The other thing I'd check is if the cron service is running. In Centos:

service crond status

You can also check it with:

ps -ef | grep crond

Luis Alberto Barandiaran

Posted 2019-06-21T13:35:17.753

Reputation: 225

Thank you for your answer. However my OS is Red Hat SunOS Unfortunately I do not have the directory /var/log/cron. It looks like service binary is not used in this OS. Finally If execute the command ps -ef | grep "cron" I see one process running – birdman – 2019-06-21T13:54:15.603

Check this thread: https://stackoverflow.com/questions/4984725/how-to-test-a-weekly-cron-job

– Luis Alberto Barandiaran – 2019-06-22T17:42:55.710