Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/sh
- #
- #
- #
- PATH=/bin:/usr/bin
- progname=$(basename $0)
- #### ligne à modifier a sa convenance
- SITE_CRONTAB=/site/etc/crontab.local
- if [ ! -f $SITE_CRONTAB ] ; then
- echo "$SITE_CRONTAB not found, aborting" >&2
- exit 1
- fi
- preview=0
- diff=0
- while getopts :pd OPT; do
- case $OPT in
- p)
- preview=1
- ;;
- d)
- diff=1
- ;;
- *)
- echo >&2 "usage: $progname [-p] [-d]"
- exit 2
- esac
- done
- shift `expr $OPTIND - 1`
- OPTIND=1
- CRONTAB=/etc/crontab
- new_crontab=/tmp/crontab.new.$$
- tag="Site custom part"
- start_tag="START $tag"
- end_tag="END $tag"
- trap "/bin/rm -f $new_crontab" EXIT
- (
- echo "# $start_tag"
- cat $SITE_CRONTAB
- echo "# $end_tag"
- sed -e "/$start_tag/,/$end_tag/d" $CRONTAB
- ) | sed -e '/^ *$/d' >$new_crontab
- [ $preview -eq 1 ] && exec cat $new_crontab 2>&1
- [ $diff -eq 1 ] && exec diff -t $CRONTAB $new_crontab
- if cmp -s $CRONTAB $new_crontab ;then
- echo "no changes" >&2
- exit
- fi
- # backup
- cp -p $CRONTAB $CRONTAB.prev
- # apply
- cat $new_crontab > $CRONTAB
- # restart
- cd /tmp
- for action in stop start
- do
- env - /usr/syno/etc/rc.d/S04crond.sh $action
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement