Cron

Chester Wyke December 07, 2022 Updated: April 15, 2025 #debian

Source: https://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/

Open file to edit

crontab -e

Format

a b c d e /path/command

Options other than number

Source: https://crontab.guru/every-5-minutes

Example every 5 minutes

*/5 * * * * date >> ~/date.txt

Special @ shortcuts

Source: https://www.linode.com/docs/guides/schedule-tasks-with-cron/#special-cron-syntaxes

Example Usage

@reboot date >> ~/test_cron.txt

Test Cron

Simple Test

Open Crontab

crontab -e

Add line to bottom and save (Ensure there is a new line at the end of the line)

* * * * * date >> ~/date.txt

Wait one minute and confirm that it works

More involved test that uses a script

Overview: Create test script and set cron to run script

Create temp folder

mkdir ~/tmp

Create test script

echo 'date >> ~/tmp/cron_result.txt' > ~/tmp/cron_test.sh
chmod 700 ~/tmp/cron_test.sh
ls -l ~/tmp

Open Crontab

crontab -e

Add line to bottom and save (Ensure there is a new line at the end of the line)

* * * * * ~/tmp/cron_test.sh

Wait one minute and confirm that it works

cat ~/tmp/cron_result.txt