1834453 Members
2142 Online
110067 Solutions
New Discussion

Re: Script for recycle.

 
syedar
Advisor

Script for recycle.

Hi all,

I need script to recycle the debug logs after every 30 or 60 minutes. Just rename existing file and keep at least two copies.please proivde me an example of it.

Thanks.
5 REPLIES 5
OldSchool
Honored Contributor

Re: Script for recycle.

crudely, it can be done with something along the lines of :

if [ -e debug_log.old ]
then
cp debug_log.old debug_log.older
fi

cp debug.log debug_log.old

> debug.log


note:

the reason *not* to use move in this case is that if something has file open, it will continue writing to the .old file.

depending on how often entries are written to the log, you might loose a few when the existing file is cleared with the ">".

once the script works as desired, you can stick it in cron to run at whatever times / intervals desired.
Aneesh Mohan
Honored Contributor

Re: Script for recycle.

Hi,

Using cron execute the below script according to your timing.

sample script
---------------

#!/usr/bin/ksh
for i in 1
do
cp log copy_1_`date +%Y%m%d%H%M%S`
cp log copy_2_`date +%Y%m%d%H%M%S`
>log
done

Please change the log destinations.

Aneesh
OldSchool
Honored Contributor

Re: Script for recycle.

"#!/usr/bin/ksh
for i in 1
do
cp log copy_1_`date +%Y%m%d%H%M%S`
cp log copy_2_`date +%Y%m%d%H%M%S`
>log
done
"

uh...doesn't that give you two copies of the same log????
Arturo Galbiati
Esteemed Contributor

Re: Script for recycle.

Hi,
use logrotate tool for this purpose. You can download the depot @
http://hpux.connect.org.uk/hppd/hpux/Sysadmin/logrotate-2.5/

This is very simple, u can play with it easily (and without writing lines of code).

HTH,
Art
Arturo Galbiati
Esteemed Contributor

Re: Script for recycle.

Hello,
please, since people spent time to provide you help, please, spent your time to assign points:
http://forums13.itrc.hp.com/service/forums/questionanswer.do?threadId=1387538

Rgds,
Art