- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Trim a log file by date
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2002 08:04 AM
03-04-2002 08:04 AM
Trim a log file by date
I have scripts that run on a box that need to have log files for the past two months. However the files do get quite large, and I need to trim them to only include the pat 60 days. Here is an example of the output of the log file:
Mon Feb 11 15:07:34 EST 2002 RECESS Not Valid.
Mon Feb 11 15:07:34 EST 2002 RECESS Not Valid.
Mon Feb 11 15:07:34 EST 2002 RECESS Not Valid.
Mon Feb 11 15:07:34 EST 2002 RECESS Not Valid.
Mon Feb 11 15:07:34 EST 2002 RECESS Not Valid.
Mon Feb 11 15:07:34 EST 2002 RECESS Not Valid.
Mon Feb 11 15:07:34 EST 2002 RECESS Not Valid.
Mon Feb 11 15:07:34 EST 2002 RECESS Not Valid.
Mon Feb 11 15:07:34 EST 2002 Bulding DataLog File test_A87026.1_I9-REC3-C_01
Mon Feb 11 15:07:34 EST 2002 ./RECZ01EA.tcl: RECZ01EA A87026.1 I9-REC3-C Finished.
My question is how do I create the script to only remove entires older than 60 days?
There could be any number of entries ranging from none in a day, to 100 in a day, so just tailing the end of the file won't work...
thanks for the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2002 08:36 AM
03-04-2002 08:36 AM
Re: Trim a log file by date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2002 08:51 AM
03-04-2002 08:51 AM
Re: Trim a log file by date
This should be fairly close. The idea is to parse that date format into a numerical month, day, year format and then use that to feed me universal date hammer 'caljd.sh'. It returns the number of days since ~Jan 1, 4713BCE (the Julian Day). If we compare the today's Julian Day to that of your log entry and the age is greater than 60 we simply don't echo the line.
I'll do this in two attachments so that you get both parts:
The general idea is this:
#!/usr/bin/sh
TDIR=${TMPDIR:-/var/tmp}
PID=$$
TF1=${TDIR}/X${PID}_1.txt
LOGFILE=mylogfile
cat ${LOGFILE} | awk -f trim.awk > ${TF1}
STAT=$?
if [ ${STAT} -eq 0 ]
then
mv ${TF1} ${LOGFILE}
else
rm -f ${TF1}
fi
exit ${STAT}
Here is the first part, 'trim.awk'. If you like, you could make it a part of the above script with a 'here doc'.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2002 08:51 AM
03-04-2002 08:51 AM
Re: Trim a log file by date
And now the other part, caljd.sh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2002 08:55 AM
03-04-2002 08:55 AM
Re: Trim a log file by date
live free or die
harry