[Asterisk-Users] How to prevent log files from eating my hard drive?

Matt Gibson m.gibson at voxip.ca
Tue Jul 5 13:56:23 MST 2005


Here is my script, It doesn't delete them after rotating them, just
backs them up to a seperate dir. Obviously the pretty formatting is just 
that, and not
a requirement :).

#!/bin/sh
#Rotates log files for asterisk

#variables
today=`/bin/date +%m%d%Y`
chown="/bin/chown"
mv="/bin/mv"
ls='/bin/ls -sh'

#tell asterisk to do its thing
echo
echo "---------------"
echo "#  MESSAGES   #"
echo "---------------"
/usr/sbin/asterisk -rx "logger rotate"
echo
# sleepy sleepy
#sleep 2

#set shit up
sourcef1="/var/log/asterisk/queue_log.0"
sourcef2="/var/log/asterisk/event_log.0"
sourcef3="/var/log/asterisk/asterisk_norm.log.0"
sourcef4="/var/log/asterisk/asterisk_debug.log.0"
sourcef5="/var/log/asterisk/screenlog.0"
destf1="/var/log/asterisk/old_logs/queue_log.$today"
destf2="/var/log/asterisk/old_logs/event_log.$today"
destf3="/var/log/asterisk/old_logs/asterisk_norm.log.$today"
destf4="/var/log/asterisk/old_logs/asterisk_debug.log.$today"
destf5="/var/log/asterisk/old_logs/screenlog.0.$today"

#moveem to dest dir
echo "---------------"
echo "#  QUEUE LOG  #"
echo "---------------"
if [ -f $sourcef1 ]; then
        $mv $sourcef1 $destf1
        echo "- rotated $sourcef1 to $destf1"
        $chown root:wheel $destf1
        echo "- $destf1 file attributes set"
        echo "- file size:" `$ls $destf1`
        echo
else
        echo "- no queue log to rotate"
        echo "- no queue log to give permissions to"
        echo
fi


echo "---------------"
echo "#  EVENT LOG  #"
echo "---------------"
if [ -f $sourcef2 ]; then
        $mv $sourcef2 $destf2
        echo "- rotated $sourcef2 to $destf2"
        $chown root:wheel $destf2
        echo "- $destf2 file attributes set"
        echo "- file size:" `$ls $destf2`
        echo
else
        echo "- no event log to rotate"
        echo "- no event log to give permissions to"
        echo
fi


echo "---------------"
echo "#   NORM LOG  #"
echo "---------------"
if [ -f $sourcef3 ]; then
        $mv $sourcef3 $destf3
        echo "- rotated $sourcef3 to $destf3"
        $chown root:wheel $destf3
        echo "- $destf3 file attributes set"
        echo "- file size:" `$ls $destf3`
        echo
else
        echo "no normal log to rotate"
        echo "no normal log to give permissions to"
        echo
fi


echo "---------------"
echo "#  DEBUG LOG  #"
echo "---------------"
if [ -f $sourcef4 ]; then
        $mv $sourcef4 $destf4
        echo "- rotated $sourcef4 to $destf4"
        $chown root:wheel $destf4
        echo "- $destf4 file attributes set"
        echo "- file size:" `$ls $destf4`
        echo
else
        echo "no debug logfile to rotate"
        echo "no debug log to give permissions to"
        echo
fi



echo "---------------"
echo "#  SCREEN LOG #"
echo "---------------"
if [ -f $sourcef5 ]; then
        $mv $sourcef5 $destf5
        echo "- rotated $sourcef5 to $destf5"
        $chown root:wheel $destf5
        echo "- $destf5 file attributes set"
        echo "- file size:" `$ls $destf5`
        echo
else
        echo "no screen logfile to rotate"
        echo "no screen log to give permissions to"
        echo
fi


called via cron

# this is to rotate the asterisk logs daily
58 23 * * * /etc/asterisk_logr.sh 1> /dev/null


Matt



Michael Stahl wrote:

>Use a script to rotate the logs every night (by cron).  If you need one,
>I'll post what I have.
>
>That's only have the solution of course...you would have to write
>another script to delete logs > X days old.
>
>Anyone have one of those handy?
>
>-----Original Message-----
>From: Leo Burd [mailto:leob at media.mit.edu] 
>Sent: Tuesday, July 05, 2005 12:28 PM
>To: asterisk-users at lists.digium.com
>Subject: [Asterisk-Users] How to prevent log files from eating my hard
>drive?
>
>Hello there,
>
>Somehow, Asterisk log files are consuming all the space that I have in
>my hard disk...  They've already eaten 14GB and are still hungry!!  What
>shall I do?  I'm not even logging anything in verbose mode!!
>
>Help really appreciated!!
>
>Best,
>
>Leo
>
>
>_______________________________________________
>Asterisk-Users mailing list
>Asterisk-Users at lists.digium.com
>http://lists.digium.com/mailman/listinfo/asterisk-users
>To UNSUBSCRIBE or update options visit:
>   http://lists.digium.com/mailman/listinfo/asterisk-users
>  
>


-- 
Matt Gibson
Communications Director
Voxip.ca / NJ Tech Solutions Inc. 
Mobile: 1.613.868.9318
Tel: 1.314.480.4550 ex 6400
Toll Free: 1.888.999.4678 ex 6400
Email: m.gibson at voxip.ca
Fax: 1.613.761.1828





More information about the asterisk-users mailing list