webalizer not running (solved with bash script)

Discussion in 'Installation/Configuration' started by awd.pt, Jul 26, 2011.

  1. awd.pt

    awd.pt Member

    Hi all,

    after my webalizer stoped proccessing logs, it only proccesed one webhost and the stop, I had to solve the "problem".

    So I wrote this bash script to run webalizer, create htpasswd and htaccess and do a log rotation.

    I'm sharing because it might be of some use to anyone and I'm totally open to improvements on it, so please, go ahead.

    Code:
    #!/bin/bash
    TPATH=/var/www
    WEBADIR=/web/webalizer
    WEBACONF=/root/ispconfig/scripts/shell/webalizer.conf
    YEAR=`/bin/date | awk '{print $6}'`
    MONTH=`/bin/date | awk '{print $2}'`
    DAY=`/bin/date | awk '{print $3}'`
    
    case $MONTH in
            "Jan") MONTH=01;;
            "Feb") MONTH=02;;
            "Mar") MONTH=03;;
            "Apr") MONTH=04;;
            "May") MONTH=05;;
            "Jun") MONTH=06;;
            "Jul") MONTH=07;;
            "Aug") MONTH=08;;
            "Sep") MONTH=09;;
            "Oct") MONTH=10;;
            "Nov") MONTH=11;;
            "Dec") MONTH=12;;
    esac
    
    cd $TPATH
    for i in www.*
            do
    # ------- SET VARS
            URL=`ls -l $i | awk '{print $9}'`
            LDIR=`ls -l $i | awk '{print $11}'`
            USER=`ls -l $i | awk '{print $4}'`
            HTUSER=$USER"_wa"
    
    # ------- Check webalizer dir exists
            if [ ! -d $TPATH/$USER/$WEBADIR ]; then
                    mkdir $TPATH/$USER/$WEBADIR
            fi
    # ------- Process Statistics
            if [ -f $LDIR/log/$YEAR/$MONTH/web.log ]; then
                    /usr/bin/webalizer -n $URL -s $URL -r $URL -T -o $LDIR$WEBADIR -c $WEBACONF $LDIR/log/$YEAR/$MONTH/web.log
                    if [ ! -f $LDIR/log/$YEAR/$MONTH/web.log.$DAY.tgz ]; then
                            tar zcf $LDIR/log/$YEAR/$MONTH/web.log.$DAY.tgz $LDIR/log/$YEAR/$MONTH/web.log
                            rm -f $LDIR/log/$YEAR/$MONTH/web.log
                            touch $LDIR/log/$YEAR/$MONTH/web.log
                    fi
            fi
    # ------- create htacces @ webalizer dir
            if [ ! -f $TPATH/$USER/$WEBADIR/.htaccess ]; then
                    echo "AuthType Basic
                    AuthName \"Members Only\"
                    AuthUserFile $TPATH/$USER/.htpasswd
                    <limit GET PUT POST>
                    require valid-user
                    </limit>" > $TPATH/$USER/$WEBADIR/.htaccess
            fi
    
    # ------- creat htpasswd at webdir
            if [ ! -f $TPATH/$USER/.htpasswd ]; then
                    echo $HTUSER:`cat /etc/shadow | grep $HTUSER | sed 's/:/ /g' | awk '{print $2}'` > $TPATH/$USER/.htpasswd
            fi
    done
    
    Thank you
     

Share This Page