nettoyage de logs webobjects
This commit is contained in:
parent
458ccd3df1
commit
8af50f4b91
|
@ -0,0 +1,90 @@
|
|||
#!/bin/bash
|
||||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
source "$(dirname "$0")/lib/ulib/ulib" || exit 1
|
||||
urequire DEFAULTS
|
||||
|
||||
function display_help() {
|
||||
uecho "$scriptname: supprimer les fichiers de log inutiles dans /var/log/WebObjects
|
||||
|
||||
USAGE
|
||||
$scriptname [options]
|
||||
|
||||
OPTIONS
|
||||
-u, --useless
|
||||
Supprimer les logs inutiles. C'est l'option par défaut
|
||||
-a, --all
|
||||
Supprimer tous les logs
|
||||
-t, --today
|
||||
Supprimer tous les logs du jour"
|
||||
}
|
||||
|
||||
what=useless
|
||||
args=(
|
||||
--help '$exit_with display_help'
|
||||
-u,--useless what=useless
|
||||
-a,--all what=all
|
||||
-t,--today what=today
|
||||
)
|
||||
parse_args "$@"; set -- "${args[@]}"
|
||||
|
||||
run_as_root "$@"
|
||||
|
||||
count=0
|
||||
cd /var/log/WebObjects || die
|
||||
|
||||
case "$what" in
|
||||
useless)
|
||||
einfo "Suppression des fichiers de log inutiles dans /var/log/WebObjects"
|
||||
ask_yesno "Voulez-vous continuer?" O || exit
|
||||
|
||||
/bin/ls | while read f; do
|
||||
[ "${f%-[0-9]}" != "$f" ] && continue
|
||||
|
||||
# Tester la presence de "Waiting for requests..."
|
||||
if ! grep -q 'Waiting for requests...$' "$f"; then
|
||||
echo "$f: no 'Waiting for Requests...'"
|
||||
/bin/rm -f "$f" || die
|
||||
count=$(($count + 1))
|
||||
continue
|
||||
fi
|
||||
|
||||
# Tester la presence de contenu apres Waiting for requests..."
|
||||
if grep -v "CookieParser: Found a null cookie value in: " "$f" | tail -n 1 | grep -q 'Waiting for requests...$'; then
|
||||
echo "$f: empty log"
|
||||
/bin/rm -f "$f" || die
|
||||
count=$(($count + 1))
|
||||
continue
|
||||
fi
|
||||
done
|
||||
;;
|
||||
|
||||
all)
|
||||
einfo "Suppression de TOUS les fichiers de logs dans /var/log/WebObjects"
|
||||
ask_yesno "Voulez-vous continuer?" O || exit
|
||||
|
||||
/bin/ls | while read f; do
|
||||
if [ "${f%-[0-9]}" = "$f" ]; then
|
||||
echo "$f"
|
||||
/bin/rm -f "$f" || exit 1
|
||||
count=$(($count + 1))
|
||||
fi
|
||||
done
|
||||
;;
|
||||
|
||||
today)
|
||||
einfo "Suppression des fichiers de logs DU JOUR dans /var/log/WebObjects"
|
||||
ask_yesno "Voulez-vous continuer?" O || exit
|
||||
|
||||
now="$(date +%Y%m%d)"
|
||||
|
||||
/bin/ls | grep -- "-[0-9]*\\.$now[0-9]*$" | while read f; do
|
||||
echo "$f"
|
||||
/bin/rm -f "$f" || exit 1
|
||||
count=$(($count + 1))
|
||||
done
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $count -gt 0 ]; then
|
||||
enote "$count fichiers supprimés"
|
||||
fi
|
Loading…
Reference in New Issue