Skip to content

Instantly share code, notes, and snippets.

@lillesvin
Last active March 2, 2016 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lillesvin/dd73a92441e19e6a4162 to your computer and use it in GitHub Desktop.
Save lillesvin/dd73a92441e19e6a4162 to your computer and use it in GitHub Desktop.
Hack to run bi-weekly jobs via Cron
# Hack to run every 2nd Tuesday:
# - Cron notation to run every Tuesday
# - PHP exits with (effectively): date("W") % 2
# - Hacked to remove all '%' because cron can't handle them
# - Use shell chaining (&& and ||) to determine even/odd weeks
# - && for even week numbers, || for odd
# So to run `echo "Still here ..."` every other Tuesday at 10:30 AM:
30 10 * * 2 php -r 'exit((int)fmod(date("W"),2));' && echo "Still here ..."
# Note: PHP can obviously be replaced with anything that
# can be executed in a similar fasion and doesn't contain
# percentage signs (%), e.g. Ruby:
# `ruby -rdate -e 'exit (Date.today.cweek.modulo(2))'`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment