Overcoming Cronjob Setup Issues – A Guide for Success | Setup Timezone

timezone cronjob

In recent days, I encountered challenges while setting up my cronjob. Initially, I opted for the * * * * * setting, but it didn’t seem to work when I specified a specific time. Despite extensive online searches, I couldn’t find a comprehensive guide to resolve the issue.

However, today, my Guru imparted a valuable tip. Before configuring the cronjob, it is crucial to check the server timezone, which defaults to UTC. I followed the advice and switched the timezone to Asia/Kolkata. Voila! The cron started functioning perfectly. But one more thing to remember is that the cron needs a restart after the timezone change.

Here’s how to change the timezone:

  1. To verify the current timezone, run the command: timedatectl. If it meets your requirements, you are good to proceed.
  2. If you need to change the timezone, follow these steps:
    • Get the list of available timezones using: timedatectl list-timezones
    • Search for your desired timezone, for instance, Kolkata, using: timedatectl list-timezones | grep Kolkata
    • Use the command to set the timezone, such as: sudo timedatectl set-timezone Asia/Kolkata

Lastly, verify the timezone with timedatectl to ensure a successful setup.

Then this will be the final command to restart the cron: sudo service cron restart