Linux Commands

How to Run a Crontab Monday and Thursday

Cron is one of the handy and powerful tools in Linux OS mostly used by the system administrators. Cron jobs let users run a particular task (command or a script) repeatedly at a given date and time. The cron job once set automatically run at that particular date and time without user involvement. Some of the tasks that can be handled by cron include backups of log files and database, maintenance tasks, sending emails, monitoring system status, etc. The crond is the service that runs in the background and regularly checks the /etc/crontab file, /var/spool/cron, and /etc/cron.d directories for the scheduled jobs. If the scheduled time for the cron jobs matches the OS time, the jobs are executed.

This post describes how to run a cron job every Monday and Thursday.

Crontab Syntax

The syntax of a crontab entry is as follows:

* * * * * <command-or-script>

Each * in this syntax refers to the following:

Minute (0-59) Hour (0-23) Day of Month (1-31) Month (1-12 or names) Day of Week (0-7 or names)

An asterisk (*) represents all allowed values. For instance, an asterisk in the Hour field will run the cron job every hour.

Run a Crontab Monday and Thursday

To run a cron job every Monday and Thursday, edit the crontab file using the command below:

$ crontab -e

Then add an entry for the cron job. For instance, to run a cron job every Monday and Thursday at 5:00 am, the entry would be:

0 5 * * MON,THU <command or script>

or

0 5 * * 1,4 <command or script>

If you want to run the cron job every Monday and Thursday at 5:00 pm, the entry would be:

0 17 * * MON,THU <command or script>

or

0 17 * * 1,4 <command or script>

Save and close the file.

Now, your scheduled job will run on every Monday and Thursday at specified time. However, remember that the job will not be executed if your system is down at the scheduled time.

In this post, we covered how to run a cron job every Monday and Thursday in a Linux OS. Similarly, you can schedule any task on any specific day and time using the cron jobs.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.