Giter VIP home page Giter VIP logo

cron-last-sunday's Introduction

cron-last-sunday

Cron Last Sunday is the solution for those picky admins that always wanted to run a task the third Thursday of the Month, or maybe the first Monday, whatever.

Read a short intro at my blog.

Install

Copy run-if-today to ~/bin for private use:

cp -av run-if-today ~/bin/

Or /usr/local/bin/ for use by all system users:

cp -av run-if-today /usr/local/bin/

Usage

run-if-today accepts two parameters, nth-day and day-of-week:

run-if-today 1 Sat # Checks for the first Saturday of the month

run-if-today 3 Mon # 3rd Monday

Keep in mind the day of week must have 3 letters starting with a capital letter. Check "date +%a" for today.

Sun, Mon, Tue, Wed, Thu, Fri, Sat

Using this is rather simple, the script "run-if-today" evaluates its parameters and returns true or false 'a la bash' i.e. 0 or 1, then with the && operator we use it to execute tasks with cron, like this:

30 6 * * 6 root run-if-today 1 Sat && /root/myfirstsaturdaybackup.sh

If run-if-today returns 1 (false in Bash) then the && (and) will stop the operation and nothing happens.

You could use a * instead of 6 for the day of week, the script checks if it's Saturday and within the date range of the desired week, but in order to execute this code as little as possible it's recommended to fix a weekday so it runs at most 4 or 5 times a month.

Or you could possibly completely omit the second parameter and inherit it from cron since we are already specifying parameter. For example:

30 6 * * 6 root run-if-today 1 && /root/myfirstsaturdaybackup.sh

is equivalent to previous cronjob.

cron-last-sunday's People

Contributors

respencer avatar xr09 avatar medicmomcilo avatar

Watchers

Robert Tulke avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.