Created
November 26, 2012 06:40
-
-
Save remore/4146879 to your computer and use it in GitHub Desktop.
Check and register crontab settings (just in case you are not allowed to add files under /etc/cron.d folder)
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: | |
# ControlCrontab.sh [check|register] | |
if [ `echo $USER` != "hogehoge" ]; then | |
echo "you must be hogehoge!!!!" | |
exit 0 | |
fi | |
if [ $# -eq 1 ] && [ $1 = "check" ]; then | |
crontab -l | |
exit 0 | |
fi | |
if [ $# -eq 1 ] && [ $1 = "register" ]; then | |
HOSTNAME=`hostname;` | |
CRONTABS="/opt/scripts/crontabs/${HOSTNAME}/*.crontab" | |
if [[ "${HOSTNAME}" =~ ^SERVER-NAME-0[1-3] ]]; then | |
diff <(crontab -l) <(cat ${CRONTABS}) | |
echo -n "you are now in ${HOSTNAME}. are you sure to update? type [y] if ok: " | |
read ANSWER | |
if [ ${ANSWER} = "y" ]; then | |
DATETIME=`date +"%Y%m%d-%H%M%S";` | |
BACKUPDIR="/opt/scripts/crontabs/${HOSTNAME}/backup/" | |
crontab -l > ${BACKUPDIR}${DATETIME}.crontab.log | |
cat ${CRONTABS} | awk "BEGIN{print \"# Registered at: ${DATETIME}\" } {print}" | crontab | |
echo "successfully finished." | |
else | |
echo "operation is canceled." | |
fi | |
else | |
echo "please move to other SERVER" | |
fi | |
exit 0 | |
fi | |
echo " usage:" | |
echo " ControlCrontab.sh [check|register]" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment