crontab is the default tool for automating repetitive tasks.
Example:
Runs backup.sh every night at 2:00 AM and appends both standard output and error messages to backup.log
0 2 * * * /home/student/scripts/backup.sh >> /home/student/logs/backup.log 2>&1
Automatically dump databases every night at midnight, compress the files, and upload them to cloud storage.
0 0 * * * /usr/local/bin/pg_dumpall | gzip > /backups/db_$(date +\%F).sql.gz
[Minute (0-59)] [Hour (0 - 23)] [Day of Month (1 - 31)] [Month (1 - 12 or JAN-DEC)] [Day of Week (0 - 6 or SUN-SAT)] [Command]
Range(-)
Use to specify range
Example: If want trigger every weekday , insert MON-FRI as [Day of Week]
Wildcards(*)
Use to present other characters
Example: If want trigger every day , insert * * * as [Day of Month] [Month] [Day of Week]
Commas(,)
Use to specify multiple
Example: If want trigger multiple times (8:00 AM, 12:00 PM, and 6:00 PM) in single day , insert 08,12,18 as [Hour]
Step values(/)
Syntax: [Any Parameters]/[Step]
Example: If want trigger every 15 mins, insert */15 as [Minute]
Open crontab
crontab -e
If non-root user, crontab -e -u [User], example: crontab -e -u student
Edit command in crontab
Press Esc --> I
Example: 42 * * * * logger "Hello" ( Enter Hello into system log when time at **:42 )
Press Esc --> :wq --> Enter to save.
Verify command
crontab -l
If non-root user, crontab -l -u [User], example: crontab -l -u student
Check current time and wait pass the scheduled time
date
Verify result in system log
journalctl -e | grep [Text]
Example: journalctl -e | grep "Hello"
Sep 15 14:42:01 localhost.localdomain CROND[5069]: (student) CMD (logger "Hello")
Sep 15 14:42:01 localhost.localdomain student[5069]: Hello
7. Remove the crontab job
crontab -r
If non-root user, crontab -r -u [User], example: crontab -r -u student
8. Verify
crontab -l
If non-root user, crontab -l -u [User], example: crontab -l -u student
Result
student@localhost:~$ crontab -e
crontab: installing new crontab
Backup of student's previous crontab saved to /home/student/.cache/crontab/crontab.bak
student@localhost:~$ crontab -l
42 * * * * logger "Hello"
student@localhost:~$ date
Tue Sep 15 02:44:18 PM +08 2026
student@localhost:~$ journalctl -e | grep "Hello"
Sep 15 14:42:01 localhost.localdomain CROND[5069]: (student) CMD (logger "Hello")
Sep 15 14:42:01 localhost.localdomain student[5069]: Hello
Sep 15 14:42:01 localhost.localdomain CROND[5067]: (student) CMDEND (logger "Hello")
student@localhost:~$ crontab -r
Backup of student's previous crontab saved to /home/student/.cache/crontab/crontab.bak
student@localhost:~$ crontab -l
no crontab for student