Cron job Syntax
In managing crontab entries, various flags serve specific purposes for adding and viewing cron jobs.
- crontab -e: This flag is used to edit crontab entries, allowing you to add, delete, or modify cron jobs according to your requirements.
- crontab -l: By employing this flag, you can list all the cron jobs associated with the current user, providing an overview of the scheduled tasks.
- crontab -u username -l: When utilizing this flag, you can list the cron jobs belonging to another user. This allows for inspecting the scheduled tasks of a specified username.
- crontab -u username -e: This flag enables the editing of cron jobs for another user. It provides the capability to modify or add cron jobs for the specified username.
When viewing the list of cron jobs, the output typically resembles the following example:
# Cron job example
* * * * * sh /path/to/script.sh
In this example, a cron job is defined to execute the script located at “/path/to/script.sh” at intervals specified by the time parameters (* * * * *).
Here, we can see the indication of time as shown
Time |
Value |
Description |
---|---|---|
Minutes |
0-59 |
Specific minute |
Hours |
0-23 |
Specific hour |
Days |
1-31 |
Day of the month |
Months |
1-12 |
Month of the year |
Weekdays |
0-6 |
Day of the week . Here, 0 is implicitly referred to as “Sunday”. |
sh
represents that the script is a bash script and should be run from/bin/bash
./path/to/script.sh
specifies the path to script.
If we Summarize the cron job syntax:
* * * * * sh /path/to/script/script.sh
| | | | | |
| | | | | Command or Script to Execute
| | | | |
| | | | |
| | | | |
| | | | Day in Week(0-6)
| | | |
| | | Month in Year(1-12)
| | |
| | Day in Month(1-31)
| |
| Hour(0-23)
|
Min(0-59)
How to Automate Tasks with Cron Jobs in Linux?
Tired of repeating the same tasks every day? Feeling like your computer’s to-do list is multiplying faster than dust bunnies? Well, say goodbye to manual madness and hello to cron jobs! Think of them as your robot assistants in the land of Linux, diligently taking care of those repetitive chores while you’re free to conquer bigger techy mountains.
Imagine waking up to a sparkling clean inbox (thanks to automatic email deletion) or finding your files neatly backed up every night (without lifting a finger). With cron jobs, these automation superpowers are just a few lines of code away.
Table of Content
- What is Cron?
- What is Crontab?
- Starting with Crontab File
- Crontab Initialization
- How to List All the Cron jobs for the Current User
- How to Create New Schedules Using Crontab
- Cron job Syntax
- Cron job examples
Contact Us