How to use Cron Jobs

Cron jobs are commands run on a schedule and useful for many background tasks that need to run periodically.

Written by Chris Oliver
Updated over a week ago
Hatchbox creates cron jobs by adding them to the system cron service.

Cron Format
For help formatting Cron jobs, check out https://crontab.guru/

Cron Time Zones
Cron runs on the system time zone, which is UTC by default. Your server may be on a different time zone. 

To can see which timezone your server is configured for, run this command over SSH:
timedatectl
We recommend keeping the timezone as UTC and adjusting your cron times accordingly.

To change the system timezone, you can reconfigure tzdata and restart cron.
sudo dpkg-reconfigure tzdata
sudo service cron restart
Cron Logging
It's up to you to have your cron job log to a file. Hatchbox only installs cron jobs which do not have any special logging like processes do.

Whenever Gem
The "whenever" gem is a Rubygem that allows you to specify your cron jobs in Ruby code.

If Hatchbox detects whenever is installed and finds a config/schedule.rb file, it will run whenever to update the crontab.
 
Note: Cron jobs from whenever will not be visible in the Hatchbox UI.

Was this article helpful?