Skip to content

Instantly share code, notes, and snippets.

@lillesvin lillesvin/cron-hack
Last active Mar 2, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.