Created
February 29, 2012 13:58
-
-
Save xtetsuji/1941043 to your computer and use it in GitHub Desktop.
return success code on "end of month" and "leap year"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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