Cron Tab for Odd or Even days only

Cron tab tasks are easy to do after you learn the syntax. Until I understood how to schedule tasks with cron, I have googled a lot, every time I needed to do something in cron.

Today, I will show you how to make your task run in all the odd or even days, of a month.

Let’s make a convention. We will use 30 days as the base for the even-days and 31 days for executing in the odd days only. Yes, I know that not all the months in a year have the same number of days. And I also know that there is a February month having 28 or 29 days only, but this may not concert you because the task job will work perfectly and in February will just not match the last 2-3 days.

Type cron -e and copy/paste this (don’t forget to do chmod +x /path/to/script for the script to be executed):

# Will only run on odd days:
0 0 1-31/2 * * /path/to/script

# Will only run on even days:
0 0 0-30/2 * * /path/to/script

Share and Enjoy

  • Twitter
  • Facebook
  • Google Plus
  • Email
  • RSS
Tagged with: , , , , , , ,
Posted in The Linux and Unix Articles!
One comment on “Cron Tab for Odd or Even days only
  1. evelgis says:

    this website for me is very good

Leave a Reply

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

*

Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!