Operating System - HP-UX
1753937 Members
9303 Online
108811 Solutions
New Discussion юеВ

shell script for log rotation

 
SOLVED
Go to solution
Shivkumar
Super Advisor

shell script for log rotation

Dear Sirs,

I want to rotate a log file based on its size. Does anyone has any shell script for this ?

Regards,
Shiv
7 REPLIES 7
Joseph Loo
Honored Contributor
Solution

Re: shell script for log rotation

hi,

do u have logrotate:

http://hpux.connect.org.uk/hppd/hpux/Sysadmin/logrotate-2.5/

regards.
what you do not see does not mean you should not believe
Yogeeraj_1
Honored Contributor

Re: shell script for log rotation

hi shiv,

see:
http://hpux.connect.org.uk/hppd/hpux/Sysadmin/logrotate-2.5/

this tool is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.

hope this helps!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Geoff Wild
Honored Contributor

Re: shell script for log rotation

Use logrotate - link above.

Mine is configured like so:

/etc/logrotate.conf

# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 5

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp -- we'll rotate them here
/var/adm/wtmp {
monthly
create 0664 adm adm
rotate 1
}


In /etc/logrotate.d dir, I have maillog and syslog.

# cat syslog
/var/adm/syslog/syslog.log {
rotate 5
weekly
postrotate
/usr/bin/kill -HUP `ps -ef |grep syslogd |awk '{print $2}'` || true
endscript
}

# cat maillog
/var/adm/syslog/mail.log {
rotate 5
weekly
}

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Rick Garland
Honored Contributor

Re: shell script for log rotation

As opposed to size, the logrotate does it job based on time.

Once per week, per month, daily, etc...

I like to rotate by month - I keep the previous 2 months on the system with older logs being on 2 different monthly backups.

Each will have a name that describes its contents and from when. Example, 'sulog.Dec2005', 'sulog.Nov2005', 'syslog.Dec2005', etc...

I know the time frames so I know which archived log file to look for.
Arunvijai_4
Honored Contributor

Re: shell script for log rotation

Hi Shiv,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=938732

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Joel Girot
Trusted Contributor

Re: shell script for log rotation

Hi Shiv,
If you prefer a shell script, here a good ksh script found on this forum some time ago.(Sorry, I forgot the name of the author). It rotate log files based on size, lifespan, It allow compression, manage the "old" files log generated by the system (eg OLDsyslog.log vs syslog.log), the number of copies to maintain, the security parameters to be applied to the files with chmod and chown. It is very simple, easy to adapt and deserves to be examined.
Regards, Joel
Michael Mendoza
New Member

Re: shell script for log rotation

Hi All,

Just want to say that the attached script by Joel above works very well in our hpux system.

Thanks!
Michael