Cron job basics

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2022-05-26

Here's how to do a few basic things with cronjobs:

Inspect their logs

grep CRON /var/log/syslog

Run a program once per minute:

* * * * * /folder/myprogram

Each star represents a unit of time, with the first being the minute, the next the hour, day (of month), month (of year), and - confusingly since it breaks the order established - the day of the week.

View all cron jobs in your system

$ crontab -l

Add a cron entry using a script:

(crontab -l 2>/dev/null; echo "* * * * * php /path/to/artisan horizon") | crontab -

Source: https://stackoverflow.com/questions/4880290/how-do-i-create-a-crontab-through-a-script

Clear all cron entries

crontab -r

Start a long-running process