The easiest way to find the syntax for your crontab tasks on Linux.
How to schedule a task on Linux systems?
To schedule a task on Linux, use this tool and follow these steps:
- Open the crontab with:
sudo crontab -e(if you don’t have an administrator account)
- Paste the green code provided by this tool
- Save and exit (with Nano: CTRL+O, Enter, CTRL+X)
What shortcuts are available in the crontab?
This tool will be useful for common schedule settings, like hourly, daily and weekly tasks. It will also help you to program scripts to run at specific times (like 8:15 and 16:47 each day). But you can also use some shortcuts to match specific needs, here are a few examples:
- @reboot: start a script when the system restarts.
- @hourly: run a task once an hour (equivalent to 0 * * * *)
- @daily: run once a day (same as 0 0 * * *)
- @weekly: run once a week (same as 0 0 * * 0)
- @monthly: run once a month (same as 0 0 1 * *)
- @yearly: run once a year (same as 0 0 1 1 *)
Remember to use them for simple schedule.
How to check if a cron job run when expected?
The easiest way to check if a cron task is running as expect is to check the log file. On Red Hat-based systems, it should be in /var/log/cron while on Debian based systems it should be in /var/log/auth.log or /var/log/syslog.
Another way is to redirect the output of your task to your own log file, for example:
* * * * * /home/user/myscript.sh > /home/user/myscript.log