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
Next revisionBoth sides next revision
purging_script [2013/10/10 10:24] dodgerlinux:purging_script [2018/04/17 08:51] – ↷ Page moved from lamp:purging_script to linux:purging_script dodger
Line 4: Line 4:
  
 This script write 2 logs each time : This script write 2 logs each time :
-$(dirname purge_files.sh)/logs/purge_files_$(date +.log+  * ''$(dirname purge_files.sh)/logs/purge_files_$(date +%Y%m%d%H%M).log'' 
 +  * ''$(dirname purge_files.sh)/logs/purge_files_$(date +%Y%m%d%H%M).err'' 
 +So you will have detailed the script actions+errors there
  
 ====== Instructions ====== ====== Instructions ======
  
 ===== 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 47: Line 51:
 ==== Sample Config ==== ==== Sample Config ====
 <code>#path,mask,action,param1,param2,param3 <code>#path,mask,action,param1,param2,param3
-/home/root/purge_files,*.log,bydate,+4,,,,,  +# Allways purge the script logs 
-/home/root/purge_files,*.err,bydate,+4,,,,,+/home/scripts/purge_files/logs,*.log,bydate,+4, 
 +/home/scripts/purge_files/logs,*.err,bydate,+4,
  
-/var/log/httpd,*.gz,bydate,+20,,,, +# Target: nginx logs 
-/var/log/nginx,*.gz,bydate,+20,,,,+/var/log/nginx,*.gz,bydate,+20,,
  
-/home/backup/files,*.tar.gz,bydate,+8,,,, +# Objetivo : Oracle listerner trace files 
-/home/backup/files,*.excluded,bydate,+8,,,, +/u01/app/oracle/diag/tnslsnr,*trc,bydate,+15,4
-/home/backup/files,*.log,bydate,+8,,,, +/u01/app/oracle/diag/tnslsnr,*trm,bydate,+15,4,
-/home/backup/mysql,*.sql.bz2,bydate,+8,,,, +
-/home/owncloud/data,*.log,bydate,+10,,,,+
 </code> </code>
  
Line 106: Line 109:
  
 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 150: Line 153:
     [[ "${PARAM2}" ]] && AUX="-maxdepth ${PARAM2}" && MESSAGE="%s${MESSAGE} and maxdepth ${PARAM2}"     [[ "${PARAM2}" ]] && AUX="-maxdepth ${PARAM2}" && MESSAGE="%s${MESSAGE} and maxdepth ${PARAM2}"
     printf "%s${MESSAGE}\n"     printf "%s${MESSAGE}\n"
-    # workaround for eval "bug" 
-#    local AUXDIR="/tmp/$(date +%s)" 
-#    mkdir ${AUXDIR} 
-#    cd ${AUXDIR} 
     eval find ${FOLDER} ${AUX} -name "${MASK}" ${TYPEOF} ${OPT} ${PARAM1} ${FINDCMD}     eval find ${FOLDER} ${AUX} -name "${MASK}" ${TYPEOF} ${OPT} ${PARAM1} ${FINDCMD}
-#    cd ${OLDPWD} 
-#    rm -fr ${AUXDIR} 
 } }
  
Line 205: Line 202:
 ######################################################################## ########################################################################
  
 +
 +[ ! -d ${LOGDIR} ] && mkdir -p ${LOGDIR}
  
 exec 1>> ${LOGDIR}/$(basename $0 .sh)_${MYDATE}.log exec 1>> ${LOGDIR}/$(basename $0 .sh)_${MYDATE}.log
Line 226: Line 225:
  
  
-#     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 262: Line 260:
             [[ "${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.txt · Last modified: 2022/02/11 11:36 by 127.0.0.1