[RISOLTO] Problemino logrotate e cron.daily per webalizer

Installazione, configurazione e uso di Ubuntu come server: web, ftp, mail, news, proxy, dns e altro.
Scrivi risposta
Avatar utente
Sam9999
Entusiasta Emergente
Entusiasta Emergente
Messaggi: 1983
Iscrizione: lunedì 9 giugno 2014, 8:59
Desktop: Studio Xfce
Distribuzione: Ubuntu 20.04 LTS (Focal)
Località: BO
Contatti:

[RISOLTO] Problemino logrotate e cron.daily per webalizer

Messaggio da Sam9999 »

Praticamente ho controllato e il logrotate essendo messo nel cron.daily dovrebbe partire alle 6,25 del mattino circa, invece la rotazione dei log di apache2 avviene a mezzanotte circa e quindi quando poi parte il cron.daily per webalizer alle 00:09 circa mi trova l'ultimo giorno del mese vuoto e le statistiche, di quel giorno, quindi sono solo parziali.
Effettuo una rotazione dei log di accesso del server apache2 mensilmente, questo per poter disporre dei log per le statistiche.
Mentre per awstats, lo faccio partire un po' prima di mezzanotte e quindi ho le statistiche complete, al limite mancano 5 minuti.
Awstats mette il suo script nel cron.daily, lo script è il seguente:

Codice: Seleziona tutto

#!/bin/sh
# /etc/cron.daily/webalizer: Webalizer daily maintenance script
# This script was originally written by 
# Remco van de Meent <remco@debian.org>
# and now, all rewrited by Jose Carlos Medeiros <jose@psabs.com.br> 

# This script just run webalizer against all .conf files in /etc/webalizer directory

WEBALIZER=/usr/bin/webalizer
WEBALIZER_CONFDIR=/etc/webalizer

[ -x ${WEBALIZER} ] || exit 0;
[ -d ${WEBALIZER_CONFDIR} ] || exit 0;

for i in ${WEBALIZER_CONFDIR}/*.conf; do
  # exists ?
  [ -f $i ] || continue;

  # run agains a rotated or normal logfile
  LOGFILE=`awk '$1 ~ /^LogFile$/ {print $2}' $i`;

  # empty ?
  [ -s "${LOGFILE}" ] || continue;
  # readable ?
  [ -r "${LOGFILE}" ] || continue;
  
  # there was a output ?
  OUTDIR=`awk '$1 ~ /^OutputDir$/ {print $2}' $i`;
  #  exists something ?
  [ "${OUTDIR}" != "" ] || continue;
  # its a directory ?
  [ -d ${OUTDIR} ] || continue;
  # its writable ?
  [ -w ${OUTDIR} ] || continue;

  # Run Really quietly, exit with status code if !0
  ${WEBALIZER} -c ${i} -Q || continue;
  RET=$?;

  # Non rotated log file
  NLOGFILE=`awk '$1 ~ /^LogFile$/ {gsub(/\.[0-9]+(\.gz)?/,""); print $2}' $i`;

  # check current log, if last log is a rotated logfile
  if [ "${LOGFILE}" != "${NLOGFILE}" ]; then
    # empty ?
    [ -s "${NLOGFILE}" ] || continue;
    # readable ?
    [ -r "${NLOGFILE}" ] || continue;

    ${WEBALIZER} -c ${i} -Q ${NLOGFILE};
    RET=$?;
  fi;
done;

# exit with webalizer's exit code
exit $RET;
In /etc/crontab c'è:

Codice: Seleziona tutto

sam@locale:/etc$ cat crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user	command
17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
mentre in /etc/cron.d/awstats c'è:

Codice: Seleziona tutto

# /etc/cron.d/php@PHP_VERSION@: crontab fragment for PHP
#  This purges session files in session.save_path older than X,
#  where X is defined in seconds as the largest value of
#  session.gc_maxlifetime from all your SAPI php.ini files
#  or 24 minutes if not defined.  The script triggers only
#  when session.save_handler=files.
#
#  WARNING: The scripts tries hard to honour all relevant
#  session PHP options, but if you do something unusual
#  you have to disable this script and take care of your
#  sessions yourself.

# Look for update and purge old sessions every 30 minutes
00 */4	* * *	root	[ -x /usr/share/awstats/tools/update.sh ] && /usr/share/awstats/tools/update.sh

Ora avrei da capire perché il logrotate effettua la rotazione a mezzanotte invece che la mattina e settarlo meglio, oppure da anticipare le statistiche awstat a prima di mezzanotte, ma alle 23,50 gia faccio le statistiche webalizer ed è meglio non farle in contemporanea, causa uso risorse e cpu, magari potrebbe partire alle 00,00 che in 3 minuti mi fa le statistiche, prima del logrotate, o poi sarebbe in contemporanea con il logrotate?
Qualche suggerimento ?

Al momento ho risolto così, tanto webalizer ci mette un attimo a fare le statistiche, quindi ho rimosso webalizer da /etc/cron.daily e copiato in una cartella /home/utente dopo ho editato crontab -e e configurato che parta alle 23,59, per essere certo che sia in anticipo sul logrotate. A quel'ora awstats di solito ha finito le sue statistiche, partendo alle 23,50.
-------------
S. @-M.
-------------
Scrivi risposta

Ritorna a “Ubuntu su server”

Chi c’è in linea

Visualizzano questa sezione: stonygate e 18 ospiti