Friday, February 18, 2022

[SOLVED] Crontab Linux not running at specific time

Issue

I have a crontab job that will running at 07.00 every day. i already set it

0 7 * * * /usr/bin/curl http://localhost//blablaba

it did not work

but if i replace it with

    */10 * * * * /usr/bin/curl http://localhost//blablaba

then its running every 10 minutes. but its not working if i give a specific time

for your information, i have check the server time and it shows the right time

Thanks for your help :(


Solution

Your cron expression looks correct. As it follows this format:

minute hour day-of-month month day-of-week [user] command
  0     7       *          *       *              /usr/bin/curl http://localhost//blablaba

PS: You need to add a user field if your are using the /etc/crontab file and not a user specific crontab.

So, if your cron job is defined in the /etc/crontab file, then you need to add a user field to your cron job to make it run. If it's not the case, then check your URL on the client and server side.

But, I think the best thing to do would be debugging the cron job. SO, you need to enable logging for cron jobs by doing the following:

If you are on Ubuntu:

sudo vi /etc/rsyslog.d/50-default.conf

If you are on CentOS:

sudo vi /etc/rsyslog.conf

Uncomment this line if it is commented:

#cron.*                         /var/log/cron.log

Then restart rsyslog and cron:

sudo service rsyslog restart
sudo service cron restart or sudo service crond restart

Now you can check the /var/log/cron.log file for log messages and see if there are any problems.



Answered By - Mehdi Yedes
Answer Checked By - Senaida (WPSolving Volunteer)