Page 1 of 1
Log file size

Posted:
Wed Jan 15, 2014 8:59 pm
by mdi
Hi guys,
I noticed that my MiniDlna file reached about 400Mb.
Is there any way to automatically look after the various log files and rotate them or just cut them?
Being NAS that would come handy not to waste space.
Thanks,
MDI
Re: Log file size

Posted:
Wed Jan 15, 2014 10:46 pm
by Jocko
Hi mdi,
Yes, we could do it by using a small daemon logrotate but currently it's not implemented with the firmware.
You could also write a small shell script which rotate the log file if its size is too big and use cron to run yours script
Here an example
- Code: Select all
#!/bin/sh
if [ $# != 1 ]
then
MSIZE=1024
else
if [ $(echo $1 | grep -v [a-Z] | wc -l) -eq 0 ]
then
MSIZE=1024
else
MSIZE=$1
fi
fi
LOG='/share/1000/minidlna/database/minidlna.'
echo ${LOG}log
if [ -f ${LOG}log ]
then
SIZELOG=`du -b ${LOG}log|cut -f1`
SIZELOG=`expr $SIZELOG / 1024`
echo log size: $SIZELOG kB
if [ $SIZELOG -gt $MSIZE ]
then
cp -f ${LOG}log ${LOG}0
echo '' > ${LOG}log
echo Log has been move ...
fi
else
echo Log not found
fi
if you don't set a max size as option in the shell command, by default the script rotates the log if the size is bigger than 1MB)
Re: Log file size

Posted:
Sun Jan 19, 2014 11:41 am
by mdi
Thank you so much for your answer, I will use a script.
Could you please be so kind to suggest the logs which should be managed/checked among the ones generated in the NAS?
So I can create something to control the size for all of them.
I'm thinking about something like this:
find / -name "*.log" -size '+1024k' -exec my_rotation_script.sh {} \;
..where my_rotation_script.sh operates on 1 file given as a parameter.
In this case the script doesn't even have to check the sizes, it must only "backup" the log and touch a new log file, very simple.
I'm not sure if that is safe/appropriate.... (suggestions welcomed) :)
Thank you,
MDI
Re: Log file size

Posted:
Sun Jan 19, 2014 3:54 pm
by rafesl
mdi wrote:Hi guys,
I noticed that my MiniDlna file reached about 400Mb.
Is there any way to automatically look after the various log files and rotate them or just cut them?
Being NAS that would come handy not to waste space.
Thanks,
MDI
I had a problem with that similar thing recently and installed a patch the lads provided.
check in Board index ยป Lacie Network Space vs2. It shoudl be there.
Rafe
Re: Log file size

Posted:
Mon Jan 20, 2014 10:19 am
by Jocko
mdi wrote:..where my_rotation_script.sh operates on 1 file given as a parameter.
In this case the script doesn't even have to check the sizes, it must only "backup" the log and touch a new log file, very simple.
I'm not sure if that is safe/appropriate.... (suggestions welcomed) :)
Yes it's an easy way to do it but for all log file (system and data partition) :mrgreen:
And there can have many log files and maybe some ones shouldn't backup.
So I suggest to use this command line
- Code: Select all
find /share/1000/minidlna/database -name "*.log" -size '+1024k' -exec my_rotation_script.sh {} \;
Re: Log file size

Posted:
Sun Jan 26, 2014 11:58 am
by mdi
Hi Jocko,
in order to schedule it, should I update the active_jobs.cron file?
Where do you suggest to place my_rotation_script.sh?
I expect that the scripts runs as root...
Thanks for advising,
MDI
Re: Log file size

Posted:
Sun Jan 26, 2014 12:54 pm
by Jocko
Hi mdi,
All jobs run as root with the firmware (it's why there is a warning in the cron menu).
So you can save your my_rotation_script.sh everywhere : for example in the fvdw share.
To be sure that your script will run : you must begin the command line by a /bin/sh (so if you forget to set run permissions on your script or you edit it via webdav, the script always runs)
so use this command line
- Code: Select all
/bin/sh /share/1000/fvdw/my_rotation_script.sh
---edit---
I made an error on the path (forgot fvdw)
Re: Log file size

Posted:
Sun Jan 26, 2014 1:33 pm
by mdi
Thanks a lot Jocko, I will follow your suggestions! :)