• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Run cron job alternate week day

February 16, 2014 by Sharad Chhetri 2 Comments

In this post we will learn,Run cron job alternate week day.
Today, I met with very good question i.e how to run cron job alternate week day. The user wants to run the script in alternate Saturday.When I read this question first time,it make me to take a pause for a while. Later thinking on some more logic,I ended up with nice way to accomplish this task .

What is cron

Cron is a software utility,basically a job scheduler in Linux and Unix like operating system.
Cron information are saved in crontab which is also know as cron table.The format of writing crontab is given below

Minute Hour date-Of-Month Month Day-Of-Week /path/of/command-script

Task : We got a task to run cron job alternate week day. For eg. run a cronjob in alternate Monday,Tuesday,thursday etc.

See given below examples

Time to run script : 12.30 AM
Month : Run the script every month
Day of Week : Alternate day of week

Day of week represented in Crontab as follows

Sunday = 0
Monday = 1
Tuesday = 2
Wednesday = 3
Thursday = 4
Firday = 5
Saturday = 6

On alternate Monday

30 00 1-2,15-16,29-31 * 1 give-path-of-script-command

On alternate Tuesday

30 00 1-3,15-17,29-31 * 2 give-path-of-script-command

On alternate Wednesday

30 00 1-4,15-18,29-31 * 3 give-path-of-script-command

On alternate Thursday

30 00 1-5,15-19,29-31 * 4 give-path-of-script-command

On alternate Friday

30 00 1-6,15-20,29-31 * 5 give-path-of-script-command

On alternate Saturday

30 00 1-7,15-20,29-31 * 6 give-path-of-script-command

On alternate Sunday

30 00 1-7,15-20,29-31 * 0 give-path-of-script-command

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. cron job not working : troubleshooting steps
  2. ss command : alternate of netstat
  3. FAQ on CentOS 7 / RHEL 7 : Alternate of ifconfig command
  4. Forgot root password ,Reset it in Run level 1
  5. Run the script using nohup without hitting enter key two times
  6. 500 OOPS: vsftpd: refusing to run with writable root inside chroot()
  7. How to run django with nginx
  8. run command in remote linux / unix system by using ssh
  9. Awesome windows run command shortcuts
  10. How to install and run ghost on Ubuntu

Filed Under: Linux

Reader Interactions

Comments

  1. Vineeta Shahee says

    July 29, 2021 at 10:00 am

    I feel the above expression will not work if alternate Thursday will occur on 6-14, 20-28 For example in January 2022 Thursdays will come 6th, 13th, 20th and 27th. The other issue will come for example if alternate Thursday comes between 29-31 and next Thursday comes between 1-5 job will run for 2 consecutive Thursday.

    I had similar requirement and used an approach mentioned in this link https://stackoverflow.com/questions/68472608/conditional-cron-job-expression-for-running-task-fortnightly-and-daily

    Reply
  2. Tomy says

    June 4, 2015 at 8:42 pm

    Are the entries for alternate Saturday and alternate Sunday correct ? Should they be 30 00 1-7,15-21,29-31 * 6 give-path-of-script-command .. & 30 00 1-7,15-22,29-31 * 6 give-path-of-script-command respecitvely?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

How to install pam_mysql in CentOS or Red Hat

Keep logs of user after sudo su – : Secondary Logging

How to configure htdigest in nagios server

Learn Linux Date Command With Examples

How to empty Trash through command line in Ubuntu

convert space into new line using sed command

How to set JAVA environment variables in Linux

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy