Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #!/bin/bash
  2. # rotates webserver log files
  3. # Version 1.0
  4. # Andy Dyrcz
  5.  
  6. # Files to rotate are in the format:
  7. #
  8. # FILEPREFIX.ENVIRONMENT.DATE
  9.  
  10. # Get PATHS and SITENAME from control script name
  11. # get absolute path to program folder
  12. ctl=`readlink -f "$0"`
  13. # get ServerRoot folder containing folders: bin/, conf/, log/, www/
  14. SERVERROOT=${ctl%/*/*}
  15. LOGDIR=$SERVERROOT/logs
  16.  
  17. HOST=`hostname -s`
  18. DOMAIN=`hostname -d`
  19. TYPE=$(echo $HOSTNAME | cut -c5)
  20.  
  21. # Get the ENV var set from the hostname.
  22. p="prod"
  23. q="qa"
  24. d="dev"
  25. u="uat"
  26. eval "ENV=\$$TYPE"
  27.  
  28. # prefixes for files to rotate
  29. FILEPREFIXES=(access error upstream)
  30.  
  31. # backup with timestamp, clear working file, compress after 3 days, delete after 10 days
  32. DATE=`date +%Y%m%d.%H%M`
  33. #COMPRESS="+3"
  34. #REMOVE="+10"
  35. COMPRESS="+3"
  36. REMOVE="+60"
  37. ARCH=`uname`
  38.  
  39. if [ $ARCH == "Darwin" ]; then
  40. XARGS_REPL_ARG="-I {}"
  41. else
  42. XARGS_REPL_ARG="-i"
  43. fi
  44.  
  45. # Run compress and removes after all the sites files have been rotated.
  46. for fp in ${FILEPREFIXES[*]}; do
  47. # copy/clear current log
  48. while read file; do
  49. # echo "cp $file $file.$DATE"
  50. cp $file $file.$DATE
  51. # echo "> $file"
  52. > $file
  53. done < <( find $LOGDIR/ -type f -name "$fp.$ENV.$DATE" )
  54.  
  55. # do archive maintenance
  56. # echo "find $LOGDIR/ -type f ! -name \"*.gz\" -mtime $COMPRESS -name \"$fp.$HOST.$ENV.*\" -exec gzip -f {} \; &>/dev/null"
  57. find $LOGDIR/ -type f ! -name "*.gz" -mtime $COMPRESS -name "$fp.$HOST.$ENV.*" -exec gzip -f {} \; &>/dev/null
  58.  
  59. # echo "find $LOGDIR/ -type f -mtime $REMOVE -exec rm -f {} \; &>/dev/null"
  60. find $LOGDIR/ -type f -mtime $REMOVE -exec rm -f {} \; &>/dev/null
  61. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement