Open In App

How to Run a Crontab Job Every Week on Sunday

Last Updated : 30 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Often a list of commands you want to run on a regular basis is contained in the crontab, along with the name of the command used to administer the list. In order to conduct tasks, Crontab employs the job scheduler cron, which is called after the Greek word for time, “chronos.” Crontab is short for “cron table.” Cron is a system function that runs on your computer and performs tasks for you on a regular basis. The schedule is known as the crontab, and the tool used to edit that schedule also goes by that name. 

Run a Crontab Job Every Week on Sunday

To run the crontab job every week in a system we can modify our crontab config files, in Linux to create a cron job for the current users we can use the crontab utility in the terminal.  Here we are discussing the following guide and commands to manage the cron jobs in Linux

1. Display and View Cron Jobs

We can view the cron jobs using the crontab utility and in order to list the all task that is scheduled and listed as cron jobs we can run this command

$ crontab -l
list-cron-jobs

 

To view and edit cron jobs, we can open the crontab file using following commands:

$ crontab -e
edit-crontab

 

2. Run a particular script or task on Sunday

Here is the basic structure of the crontab file scripting language:

Basic Structure:

MIN HOUR DOM MON DOW CMD 

Configuration:

We can write the following configuration in our crontab file to run tasks every Sunday

30    10    *    *    0 task-script-file

Here the script will be executed every Sunday at 10:30 AM. you can set your time by replacing MIN and HOUR. You can also set your own script path.

We can set it other ways as well.

Configuration:

30    10    *    *    sun    task-script-file

Where the ‘0’ and ‘sun’ are synonyms for the operation to execute on Sunday.

3. Job Scheduling using the Keyword @Weekly

The crontab keyword @weekly allows for job execution every Sunday at 12:00 AM. @weekly can be used in place of time to save time. We can’t change the command’s execution time; it will happen exactly at 12:00 AM.

So we can use @weekly, instead of writing the manual crontab value for Sunday, this is by default denotes all values to Sunday at 12:00 AM. We can write the following script:

Script:

@weekly        task-script-file

The task will be executed every Sunday at 12:00 AM by default time.

creating-cron-jobs

 

After saving this, the script will be executed in the system on every Sunday at a given time.

Conclusion:

For a handful of the tasks, many of the applications required weekly cron jobs. It contains actions like performing weekly maintenance, for instance or clearing up disc spaces, mailing lists, and other things. Any day of the week is acceptable to complete your weekly tasks. For tasks requiring a CPU and memory, the use of these resources is necessary. It is advisable to complete those tasks on a weekend day. So creating a cron job is a good idea to automate the task which is repeatedly needed to be executed.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads