Dump the code
Best ressources to improve your Python Skills

Crontab: scheduling jobs

Created 1 year ago
Posted By admin
2min read
'crontab' is a command in Unix used to schedule jobs to run periodically at fixed times, dates, or intervals. Here's a basic overview of how to use 'crontab':

Viewing the Crontab
To view the current user's crontab, you can use the following command:

crontab -l

Editing the Crontab
To edit the crontab, use the following command:

crontab -e

This opens the crontab file in the default text editor specified in your environment (often "vi" or "nano").

Crontab Syntax
The crontab file has the following syntax:

* * * * * command_to_be_executed

- The five asterisks represent the time specification for the job.
- The five fields, from left to right, represent minute (0-59), hour (0-23), day of the month (1-31), month (1-12), and day of the week (0-6, where Sunday is 0 or 7).

Examples
- To run a job every day at midnight:

0 0 * * * command_to_be_executed
  
- To run a job every hour:

0 * * * * command_to_be_executed

- To run a job every Sunday at 3:30 PM:

30 15 * * 0 command_to_be_executed

Special Characters
- An asterisk (*) means "every" for that time unit.
- A comma (,) can be used to specify a list of values. For example, '1,15' in the day field means the 1st and 15th day of the month.
- A hyphen (-) can be used to specify a range. For example, '1-5' in the day field means the 1st through 5th day of the month.
- Forward slash (/) can be used to specify intervals. For example, '*/15' in the minutes field means every 15 minutes.

Removing the Crontab
To remove the current user's crontab, use:

crontab -r

These are the basics of using "crontab" for scheduling tasks on Unix-like systems. Adjust the time specifications and command as needed for your specific use case.
Topics

Mastering Nginx

27 articles

Bash script

2 articles

Crontab

2 articles