linux:purging_script
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
purging_script [2013/10/10 09:42] – dodger | linux: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 | ||
This is script is a very simple method to drop unnecessary files from your filesystems (logs?) and rotate them so they don't growth forever :-P | This is script is a very simple method to drop unnecessary files from your filesystems (logs?) and rotate them so they don't growth forever :-P | ||
+ | |||
+ | This script write 2 logs each time : | ||
+ | * '' | ||
+ | * '' | ||
+ | So you will have detailed the script actions+errors there | ||
====== Instructions ====== | ====== Instructions ====== | ||
===== Usage ===== | ===== Usage ===== | ||
- | <code bash>/u02/admin/BAVELPRO/ | + | <code bash>/home/scripts/purge_files/ |
===== Configuration ===== | ===== Configuration ===== | ||
+ | It's a file-based configuration, | ||
< | < | ||
- | /u02/admin/BAVELPRO/ | + | CONFIGFILE=/home/scripts/purge_files/ |
</ | </ | ||
+ | |||
==== Config file sytax ==== | ==== Config file sytax ==== | ||
Each line in the config file is set of file to be analysed and purged/ | Each line in the config file is set of file to be analysed and purged/ | ||
Line 22: | Line 31: | ||
Y las opciones disponibles son (explicadas como parámetros de find) | Y las opciones disponibles son (explicadas como parámetros de find) | ||
+ | === Actions === | ||
+ | ^ path ^ mask ^ action ^ param1 ^ param2 ^ param3 ^ | ||
+ | | /path | ? | bydate | mtime | maxdepth | N/A | | ||
+ | | /path | ? | bymin | mmin | maxdepth | N/A | | ||
+ | | /path | ? | rotate | size | maxdepth | N/A | | ||
+ | | /path | ? | rotatezip | size | maxdepth | gzip parameters | | ||
+ | | /path | ? | zip | mtime | maxdepth | gzip parameters | | ||
+ | | /path | ? | dirbydate | mtime | maxdepth | N/A | | ||
+ | | /path | ? | dirbymin | mmin | maxdepth | N/A | | ||
- | path mask action | + | Description: |
- | param1 param2 | + | |
- | param3 | + | |
- | /path | + | |
- | ? bydate | + | |
- | mtime maxdepth N/A | + | |
- | /path ? bymin | + | |
- | mmin maxdepth N/A | + | |
- | /path ? rotate | + | |
- | size maxdepth N/A | + | |
- | /path ? | + | |
- | maxdepth gzip parameters | + | |
- | /path ? zip | + | |
- | mtime maxdepth gzip parameters | + | |
- | /path ? | + | |
- | mtime maxdepth N/A | + | |
- | /path ? | + | |
- | mmin maxdepth N/A | + | |
+ | * bydate : Delete files based on modification time ('' | ||
+ | * bymin : Drop files based on modification minute ('' | ||
+ | * dirbydate : Drop folders based on modification time. ('' | ||
+ | * dirbymin : Drop folders based on modification minute ('' | ||
+ | * rotate : Rotate the file ('' | ||
+ | * rotatezip : Rorate and compress the file ('' | ||
+ | * zip : Compress the file ('' | ||
- | Actions | + | ==== Sample Config ==== |
- | + | < | |
- | | + | # Allways purge the script logs |
- | bymin : elimina ficheros basándose en el minuto de modificación. (find -mmin X -type f) | + | / |
- | | + | / |
- | dirbymin : elimina directorios basándose en el minuto de modificación. (find -mmin X -type d) | + | |
- | rotate : rota el fichero (cat file > file.date && > file) | + | |
- | rotatezip : rota el fichero y lo comprime al mismo tiempo (gzip -c file > file.date.gz && > file) | + | |
- | zip : comprime el fichero (gzip file) | + | |
+ | # Target: nginx logs | ||
+ | / | ||
+ | # Objetivo : Oracle listerner trace files | ||
+ | / | ||
+ | / | ||
+ | </ | ||
Line 63: | Line 73: | ||
# (C) dodger@ciberterminal.net | # (C) dodger@ciberterminal.net | ||
# | # | ||
- | # | + | |
# Exit codes: | # Exit codes: | ||
Line 101: | Line 111: | ||
MYDATE=$(date +%Y%m%d%H%M) | MYDATE=$(date +%Y%m%d%H%M) | ||
- | CONFIGFILE=$(dirname $0)/$(basename $0 .sh).config | + | CONFIGFILE=/ |
- | LOGDIR=CONFIG=$(dirname $0)/logs/ | + | LOGDIR=$(dirname $0)/logs/ |
######################################################################## | ######################################################################## | ||
Line 125: | Line 134: | ||
| | ||
PLEASE READ | PLEASE READ | ||
- | https:// | + | https:// |
# VERY INITIAL CHECKS | # VERY INITIAL CHECKS | ||
} | } | ||
Line 146: | Line 155: | ||
[[ " | [[ " | ||
printf " | printf " | ||
- | # workaround for eval " | ||
- | # local AUXDIR="/ | ||
- | # mkdir ${AUXDIR} | ||
- | # cd ${AUXDIR} | ||
eval find ${FOLDER} ${AUX} -name " | eval find ${FOLDER} ${AUX} -name " | ||
- | # cd ${OLDPWD} | ||
- | # rm -fr ${AUXDIR} | ||
} | } | ||
Line 202: | Line 205: | ||
+ | [ ! -d ${LOGDIR} ] && mkdir -p ${LOGDIR} | ||
- | + | exec 1>> ${LOGDIR}/ | |
- | + | exec 2>> ${LOGDIR}/ | |
- | # exec 1>> ${LOGDIR}/ | + | |
- | # exec 2>> ${LOGDIR}/ | + | |
Line 225: | Line 227: | ||
- | # if [[ ! " | ||
if [[ ! " | if [[ ! " | ||
printf " | printf " | ||
Line 261: | Line 262: | ||
[[ " | [[ " | ||
[[ ! " | [[ ! " | ||
- | find ${FOLDER} ${AUX} -name " | + | find ${FOLDER} ${AUX} -name " |
;; | ;; | ||
* ) | * ) |
linux/purging_script.1381398151.txt.gz · Last modified: 2013/10/10 09:42 by dodger