Avviando questo script in un cronjob di cronpad, esso vi cancellerrà tutti i file di log antecedenti di un numero “number_days” di giorni la data di oggi.
#!/bin/bash #deljbosslog.sh #Author: Predator1987 #Description: This script delete the log of JBoss antecedents number_days from today. #Usage: First edit the variables number_days and jboss_logPath # then run script as a cronjob in crontab. #A special thanks to Nathan Coulter for its date-calc.sh number_days=5 # Number of days that keeps logs jboss_logPath=/usr/local/jboss-4.2.3.GA/server/default/log/ # Path of directory log of JBoss daysBetweenTwoDate(){ MPHR=60 # Minutes per hour. HPD=24 # Hours per day. diff () { printf '%s' $(( $(date -u -d"$TARGET" +%s) - $(date -u -d"$CURRENT" +%s))) } CURRENT=$(date -u -d $1 '+%F') TARGET=$(date -u '+%F') DAYS=$(( $(diff) / $MPHR / $MPHR / $HPD )) return $DAYS } if [ ! -d "$jboss_logPath" ]; then echo jboss_logPath does not exist as a valid directory : $jboss_logPath exit 1 fi for i in $( ls $jboss_logPath | grep server.log. | sed s/server.log.//); do daysBetweenTwoDate "$i" if [ $DAYS -gt $number_days ]; then rm $jboss_logPath/server.log.$i fi done exit 0 |
Se ti è stato utile il mio articolo, spendi un secondo del tuo tempo e dammi un +1,
Google ed io ne saremmo felici 🙂 Grazie mille 🙂