Skip to content

Instantly share code, notes, and snippets.

@xtetsuji
Created February 29, 2012 13:58
Show Gist options
  • Save xtetsuji/1941043 to your computer and use it in GitHub Desktop.
Save xtetsuji/1941043 to your computer and use it in GitHub Desktop.
return success code on "end of month" and "leap year"
#!/bin/bash
# Usage:
# # crontab: need to run some-command at end-of-month.
# 0 15 28-31 * * end-of-month.sh && some-command
set -o errexit
arg=$1
if [ $(date +%m -d "$arg tomorrow" ) != $(date +%m -d "$arg" ) ] ; then
exit 0;
else
exit 1;
fi
#!/bin/bash
# Usage:
# # crontab: need to run some-command at leap-year or not it.
# 5 18 1 3 * * leap-year.sh || some-command
# 5 18 29 2 * * some-command
set -o errexit
arg=$1
if [ "$arg" ] ; then
year=$arg
else
year=$( date +%Y )
fi
if [ $(( $year % 4 )) = 0 ] ; then
if [ $(( $year % 100 )) = 0 ] ; then
if [ $(( $year % 400 )) = 0 ] ; then
exit 0
else
exit 1
fi
else
exit 0
fi
else
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment