User Tools

Site Tools


linux:purging_script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
purging_script [2013/10/10 10:32] dodgerlinux:purging_script [2022/02/11 11:36] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== [SCRIPT] Purge script ======
 +
 ====== Description ====== ====== Description ======
 Have you ever fight with logrotate configuration files? Did you survived? Cool, this document is not for you xD Have you ever fight with logrotate configuration files? Did you survived? Cool, this document is not for you xD
Line 11: Line 13:
  
 ===== Usage ===== ===== Usage =====
-<code bash>/u02/admin/BAVELPRO/scripts/purge_files.sh</code>+<code bash>/home/scripts/purge_files/purge_files.sh</code>
 ===== Configuration ===== ===== Configuration =====
 +It's a file-based configuration, the variable inside the script which sets the file is:
 <code> <code>
-/u02/admin/BAVELPRO/scripts/purge_files.config+CONFIGFILE=/home/scripts/purge_files/purge_files.config
 </code> </code>
 +
 ==== Config file sytax ==== ==== Config file sytax ====
 Each line in the config file is set of file to be analysed and purged/rotated, the syntax is: Each line in the config file is set of file to be analysed and purged/rotated, the syntax is:
Line 107: Line 111:
  
 MYDATE=$(date +%Y%m%d%H%M) MYDATE=$(date +%Y%m%d%H%M)
-CONFIGFILE=$(dirname $0)/$(basename $0 .sh).config +CONFIGFILE=/home/scripts/purge_files/purge_files.config 
-LOGDIR=CONFIG=$(dirname $0)/logs/+LOGDIR=$(dirname $0)/logs/
  
 ######################################################################## ########################################################################
Line 130: Line 134:
          
     PLEASE READ     PLEASE READ
-    https://sites.google.com/a/voxelgroup.net/sistemas/oracle/documentacion-tecnica/rotado-de-logs-y-trazas\n"+    https://sites.google.com/a/ciberterminal.net/sistemas/oracle/documentacion-tecnica/rotado-de-logs-y-trazas\n"
     # VERY INITIAL CHECKS     # VERY INITIAL CHECKS
 } }
Line 160: Line 164:
     [[ "${PARAM2}" ]] && AUX="-maxdepth ${PARAM2}" && MESSAGE="${MESSAGE}, maxdepth ${PARAM2}"     [[ "${PARAM2}" ]] && AUX="-maxdepth ${PARAM2}" && MESSAGE="${MESSAGE}, maxdepth ${PARAM2}"
     printf "%s${MESSAGE}\n"     printf "%s${MESSAGE}\n"
 +#     printf "%s$(date +%Y%m%d%H%M%S) : Rotating files on ${FOLDER}, with filemask ${MASK}, -mtime ${PARAM1}"
 +#     [[ "${PARAM2}" ]] && AUX="-maxdepth ${PARAM2}" && printf "%s, maxdepth ${PARAM2}"
          
     case $USEZIP in     case $USEZIP in
Line 198: Line 204:
 ######################################################################## ########################################################################
  
 +
 +[ ! -d ${LOGDIR} ] && mkdir -p ${LOGDIR}
  
 exec 1>> ${LOGDIR}/$(basename $0 .sh)_${MYDATE}.log exec 1>> ${LOGDIR}/$(basename $0 .sh)_${MYDATE}.log
Line 219: Line 227:
  
  
-#     if [[ ! "${LINE,,}" =~ ^\/[a-z0-9]{1,}/[\/\_\-\ a-z0-9]{1,},[\*\.\-\_\ \#a-z0-9]{3,20},(bydate|bymin|rotate|rotatezip|zip),\+[0-9]{1,3},(|\-[a-z0-9]{1,10}),$ ]] ; then 
     if [[ ! "${LINE,,}" =~ ^\/[a-z0-9]{1,}\/[\.\/\_\ a-z0-9\-]{1,},[\*\.\_\ \#a-z0-9\-]{3,20},(dirbydate|dirbymin|bydate|bymin|rotate|rotatezip|zip),\+[0-9]{1,3}(|[kmg]),(|[0-9]{1,3}),(|\-[a-z0-9]{1,10})$ ]] ; then     if [[ ! "${LINE,,}" =~ ^\/[a-z0-9]{1,}\/[\.\/\_\ a-z0-9\-]{1,},[\*\.\_\ \#a-z0-9\-]{3,20},(dirbydate|dirbymin|bydate|bymin|rotate|rotatezip|zip),\+[0-9]{1,3}(|[kmg]),(|[0-9]{1,3}),(|\-[a-z0-9]{1,10})$ ]] ; then
         printf "%sskipping ${LINE}\nnot matching the config pattern, read instructions\n"         printf "%sskipping ${LINE}\nnot matching the config pattern, read instructions\n"
Line 255: Line 262:
             [[ "${PARAM2}" ]] && AUX="-maxdepth ${PARAM2}" && printf "%s and maxdepth ${PARAM2}\n" || printf "%s\n"             [[ "${PARAM2}" ]] && AUX="-maxdepth ${PARAM2}" && printf "%s and maxdepth ${PARAM2}\n" || printf "%s\n"
             [[ ! "${PARAM3}" ]] && PARAM3="-9fv"             [[ ! "${PARAM3}" ]] && PARAM3="-9fv"
-            find ${FOLDER} ${AUX} -name "${MASK}" -type f -mtime ${PARAM1} -exec gzip -9fv {} \;+            find ${FOLDER} ${AUX} -name "${MASK}" -type f -mtime ${PARAM1} -exec gzip ${PARAM3} {} \;
         ;;         ;;
         * )         * )
linux/purging_script.1381401148.txt.gz · Last modified: 2013/10/10 10:32 by dodger