On Linux systems, cron daemon is a robust scheduling tool that executes commands or scripts at predefined times or intervals. This approach ensures repeated tasks, such as backups or log rotations, run automatically without user intervention. Bash scripts can be seamlessly integrated into these schedules for flexible and efficient automation.
The crontab file controls how cron daemon interprets scheduling instructions. Each line in a crontab entry follows a specific five-field syntax to represent minutes, hours, days of the month, months, and days of the week. This flexible structure accommodates everything from one-time tasks to complex recurring schedules.
Storing commands in crontab ensures consistent execution, even after reboots or user logouts. Environment variables within scheduled scripts can be set to define paths or custom parameters. Relying on cron daemon helps streamline system administration and simplify automation workflows.
Steps to schedule tasks with Bash using crontab:
- Verify that cron daemon is installed on the system.
- Check its status with a command for the relevant init system (e.g., systemd).
$ systemctl status cron ● cron.service - Regular background program processing daemon Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled) Active: active (running) ...
- Open a new crontab by using the crontab edit command.
$ crontab -e no crontab for user - using an empty one crontab: installing new crontab
The default editor may vary by distribution and can be changed by setting the EDITOR environment variable.
- Add a scheduling expression with the correct five-field syntax (minute, hour, day-of-month, month, and day-of-week).
0 3 * * * /home/example/backup.sh
In this example, the script runs every day at 03:00.
- Ensure Bash scripts referenced in crontab are executable and include the correct shebang line (e.g., #!/bin/bash).
- Save and exit the editor to confirm changes in the crontab.
- List existing jobs to verify scheduled tasks.
$ crontab -l 0 3 * * * /home/example/backup.sh
- Check system logs to confirm successful task execution.
$ grep CRON /var/log/syslog Mar 7 03:00:01 hostname CRON[12345]: (example) CMD (/home/example/backup.sh)
- Remove the entire crontab if no tasks are needed.
$ crontab -r crontab: removing crontab for example
Deleting the entire crontab file cannot be undone and removes all scheduled jobs.

Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.