All pastes #836062 Raw Edit

Someone

public text v1 · immutable
#836062 ·published 2007-12-29 05:14 UTC
rendered paste body
ps ax | grep squid | awk '{print $5, $1}' | grep "(squid)" | awk '{print $2}' > /home/squid/var/logs/squid.pid

this=$(grep 'Rebuilding' /home/squid/var/logs/cache.log | awk '{print $2}' | awk -F\| '{print $1}' | sort -nr | head -1 | awk -F: '{print $1 * 3600 + $2 * 60 + $3}')

go=$(echo 0)
if [ "$this" ]; then
        echo "it was rebuilding at some point"
        that=$(grep 'Completed Validation Procedure' /home/squid/var/logs/cache.log | awk '{print $2}' | awk -F\| '{print $1}' | sort -nr | head -1 | awk -F: '{print $1 * 3600 + $2 * 60 + $3}')
        if [ "$that" ]; then
                echo "it also completed rebuilding at some point. Last Rebuild time $this, Finished rebuild time $that"
                if [ $that -gt $this ]; then
                        echo "it finished after it started, everything ok"
                        go=$(echo 1)
                else
                        echo "it finished at some earlier time, it's still rebuilding"
                fi
        else
                echo "it is still rebuilding"
        fi
else
        echo "it is not rebuilding"
        go=$(echo 1)
fi

if [ "$go" ]; then
        /home/squid/sbin/squid -k rotate
        sleep 30

        for i in $( ls /home/squid/var/logs/access.log.? );
                do
                        src=$i
                        thing=$(echo "`date +%s`" )
                        stuff=$i.$thing
                        mv $src $stuff
                done

        for i in $( ls /home/squid/var/logs/cache.log.? );
                do
                        src=$i
                        thing=$(echo "`date +%s`" )
                        stuff=$i.$thing
                        mv $src $stuff
                done

        find /home/squid/var/logs/* -type f -mtime +6 -exec rm -f {} \;
fi