Trending September 2023 # How To Use Cron Weekly With Examples? # Suggested October 2023 # Top 11 Popular |

Trending September 2023 # How To Use Cron Weekly With Examples? # Suggested October 2023 # Top 11 Popular

You are reading the article How To Use Cron Weekly With Examples? updated in September 2023 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 How To Use Cron Weekly With Examples?

Introduction to Cron Weekly

Cron weekly is the facility which helps us to schedule the jobs or tasks that need to be executed periodically every week. A daemon thread runs in the background to continuously check if the current week matches with the upcoming week that has been scheduled. After executing the job on a particular week, the week on which the task is to be executed again will automatically be increased so that the daemon thread can check and match that week with the current week each time and run the job accordingly on each week.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

What is Cron Weekly?

Each of the line in the cron tab contains 5 fields related to time and date. After those 5 fields, a command is present which is to be executed, such as backing up the data, executing some script or php file, or any other synchronization work between two tasks. There after a new line character is entered. Note that all this fields are separated from one another using a space.

The 5 fields of time and date are given below:

A minute can be represented starting from 0 to 59.

An hour can be specified by specifying a number between 0 to 23, where 0 will be midnight.

Day can be represented by using 1 to 31 numbers.

For a month, be can write numbers between 1 to 12.

Lastly, week days such as Sunday, Monday, etc., can be specified by using 0 to 6 numbers where 0 stands for Sunday.

Other than the above ones, one special string for weekly cron jobs contains “0 0 * * 0,” which will indicate that we want to execute that cron job once in a week.

Cron Weekly List

We can check the complete list of all the cron jobs that the root user schedules by using the command.


Crontab -l

The execution of the above command will retrieve all the cron jobs that the root user creates. In case if you want to display the cron jobs that a particular user creates, we will also need to mention the name of the user (username) in the command whose syntax is as shown below.


Crontab username -l

For checking the list of the cron jobs scheduled on a weekly basis that is executed once per week, you can type in the following commands.

Navigate to the cron.weekly file present inside the etc/ directory by using the below command.


Cd /etc/cron.weekly

Next, type in the ls command with the -l option.

Ls -l

The next and last thing to do is run the cat command to create a file with a particular name where the list of those jobs will be saved after creating a new file with that name.

For example, if we want the folder to be created with the name educba, we can enter the command below.


Cat educba


How to Use Cron Weekly?

We can use cron weekly, usually when you have to take the backups because the backup of the system is to be taken is usually odd, such as 2 am in the night or 12 am at midnight when the users are not using the system. But at that time, it’s not possible for a technical person to be present and initiate the command of backup and execute the same. This can be easily managed by just creating the cron job once weekly, which will then execute each week, and backup operation will be performed automatically.

Other than the above application, cron jobs can also be used for setting the operating system time as most of the time, using the NTP that is Network Time Protocol can take little time and often causes a drift. That is why we can make the setting of hardware time by using cron and system time.

One more application where we can use cron jobs in services such as iogrotate, logwatch, and rootkit hunter for task scheduling and executing the programs on a daily basis.

Examples of Cron Weekly

Given below are the examples of cron weekly:

For example, suppose that we have one task of executing a file located in the directory /etc/ EDUCBA/ cronjob/ chúng tôi once in a week using cron jobs, then we can write the command as shown below.


0 0 * * 0 /etc/ EDUCBA/ cronjob/

Or other way of specifying the same command using a string is as shown here.


@weekly /etc/ EDUCBA/ cronjob/


Note that the above command can only execute and run each week you have your system started and running.


The cron weekly is the utility available in Unix/ Linux platforms where we can schedule a particular cron job which needs to execute once per week. We can create that cron jobs by using crontab and list them using the crontab -l command. While creating, we can specify the date and time-related fields for the week or optionally a string that is provided of @weekly in the command for creating a cron weekly job.

Recommended Articles

We hope that this EDUCBA information on “Cron Weekly” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

You're reading How To Use Cron Weekly With Examples?

Update the detailed information about How To Use Cron Weekly With Examples? on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!