Advertisement
CoolRaoul

cronupdate

Oct 13th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.24 KB | None | 0 0
  1. #! /bin/sh
  2. #
  3. #
  4. #
  5. PATH=/bin:/usr/bin
  6. progname=$(basename $0)
  7.  
  8. #### ligne à modifier a sa convenance
  9. SITE_CRONTAB=/site/etc/crontab.local
  10. if [ ! -f $SITE_CRONTAB ] ; then
  11.     echo "$SITE_CRONTAB not found, aborting" >&2
  12.     exit 1
  13. fi
  14. preview=0
  15. diff=0
  16. while getopts :pd OPT; do
  17.     case $OPT in
  18.         p)
  19.             preview=1
  20.             ;;
  21.         d)
  22.             diff=1
  23.             ;;
  24.         *)
  25.             echo >&2 "usage: $progname [-p] [-d]"
  26.             exit 2
  27.     esac
  28. done
  29. shift `expr $OPTIND - 1`
  30. OPTIND=1
  31.  
  32. CRONTAB=/etc/crontab
  33.  
  34. new_crontab=/tmp/crontab.new.$$
  35.  
  36. tag="Site custom part"
  37. start_tag="START $tag"
  38. end_tag="END $tag"
  39.  
  40.  
  41. trap "/bin/rm -f $new_crontab" EXIT
  42. (
  43.     echo "# $start_tag"
  44.     cat $SITE_CRONTAB
  45.     echo "# $end_tag"
  46.     sed -e "/$start_tag/,/$end_tag/d" $CRONTAB
  47. ) | sed -e '/^ *$/d' >$new_crontab
  48.  
  49. [ $preview -eq 1 ]   && exec cat $new_crontab 2>&1
  50. [ $diff -eq 1 ]   && exec diff -t $CRONTAB $new_crontab
  51.  
  52. if cmp -s $CRONTAB $new_crontab  ;then
  53.     echo "no changes" >&2
  54.     exit
  55. fi
  56.  
  57. #       backup
  58. cp -p $CRONTAB  $CRONTAB.prev
  59. #       apply
  60. cat $new_crontab > $CRONTAB
  61. #       restart
  62. cd /tmp
  63. for action in stop start
  64. do
  65.     env - /usr/syno/etc/rc.d/S04crond.sh $action
  66. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement