<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to truncate Log file to contain one month data only in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251648#M471008</link>
    <description>The file is called dmc.log. Its an application specific log file in text format.&lt;BR /&gt;&lt;BR /&gt;Sample date string in the file is  "Sat Aug 14 18:42:19 2010."&lt;BR /&gt;&lt;BR /&gt;Yes, I need to keep exactly 1 month old data (number of days depends on the month as some months have 30 days, some have 31 and February have 29 or 28 days) in the file. &lt;BR /&gt;&lt;BR /&gt;It doesn't matter when I run the script for as long as I will be able to truncate the file with 1 month old data kept.</description>
    <pubDate>Mon, 16 Aug 2010 11:17:05 GMT</pubDate>
    <dc:creator>Robert Peregrin</dc:creator>
    <dc:date>2010-08-16T11:17:05Z</dc:date>
    <item>
      <title>How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251637#M470997</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a log file which is growing to almost 2 GB in size. I need to truncate this log file to contain only one month old data  in order to reduce its size.&lt;BR /&gt;&lt;BR /&gt;Please help in giving a procedure for this.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Robert Peregrin</description>
      <pubDate>Sun, 15 Aug 2010 07:50:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251637#M470997</guid>
      <dc:creator>Robert Peregrin</dc:creator>
      <dc:date>2010-08-15T07:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251638#M470998</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;to truncate you 0 you just need to give a &amp;gt; infront of your file.&lt;BR /&gt;&amp;gt;filename&lt;BR /&gt;&lt;BR /&gt;to truncate file with condition then you need to write a script.&lt;BR /&gt;&lt;BR /&gt;Suraj</description>
      <pubDate>Sun, 15 Aug 2010 13:44:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251638#M470998</guid>
      <dc:creator>Suraj K Sankari</dc:creator>
      <dc:date>2010-08-15T13:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251639#M470999</link>
      <description>Which logfile?  Some are ascii text (syslog.log) and some are binary (wtmps).&lt;BR /&gt;&lt;BR /&gt;It also depends on what is the date string in the file.  And whether you need exactly 31 days or just the current month or you are only going to run the script on the last/first day of the month.</description>
      <pubDate>Sun, 15 Aug 2010 15:28:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251639#M470999</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-08-15T15:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251640#M471000</link>
      <description>in SAM or the SMH tools there is a section under routine tasks where you can automatically trim log files and you can add non-standard log files to this tool and define a max size for the log file.  YOu can then trim all of them at the same time and periodically using this tool.</description>
      <pubDate>Mon, 16 Aug 2010 00:05:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251640#M471000</guid>
      <dc:creator>Emil Velez</dc:creator>
      <dc:date>2010-08-16T00:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251641#M471001</link>
      <description>Robert,&lt;BR /&gt;&lt;BR /&gt;If you want to trim the file , by reducing contents from the log file you can do so by removing first few lines, &lt;BR /&gt;1. count the lines, with wc -l logfile ,&lt;BR /&gt;2. trim it as desired.&lt;BR /&gt;&lt;BR /&gt;- If you want a gzip copy of backup of the file elsewhere you can keep a copy.&lt;BR /&gt;&lt;BR /&gt;-Example: To trim first 2000 lines from the file:&lt;BR /&gt;- stop the process writing the file.&lt;BR /&gt;- trim &lt;BR /&gt;# perl -i -ne 'print unless 1 .. 2000'  logfile.log&lt;BR /&gt;- start the process, writing to it.&lt;BR /&gt;- check size/lines.&lt;BR /&gt;&lt;BR /&gt;Hth,&lt;BR /&gt;Raj.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Aug 2010 06:09:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251641#M471001</guid>
      <dc:creator>Raj D.</dc:creator>
      <dc:date>2010-08-16T06:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251642#M471002</link>
      <description>Hi Robert:&lt;BR /&gt;&lt;BR /&gt;Create a script to switch and compress the log file.&lt;BR /&gt;&lt;BR /&gt;- Stop application&lt;BR /&gt;- mv logfile to logfile.old&lt;BR /&gt;- Initialize new logfile&lt;BR /&gt;- Start application&lt;BR /&gt;- compress the old logfile&lt;BR /&gt;&lt;BR /&gt;schedule (cron, ovo, ...)  the script in  specified dates and times.&lt;BR /&gt;&lt;BR /&gt;rgs,&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Aug 2010 07:19:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251642#M471002</guid>
      <dc:creator>rariasn</dc:creator>
      <dc:date>2010-08-16T07:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251643#M471003</link>
      <description>Thanks for your suggestions guys.&lt;BR /&gt;&lt;BR /&gt;The log file is a text file.&lt;BR /&gt;&lt;BR /&gt;The SAM utility is nice but we need the triming to be automatic. A simple script would be useful which I can run as a cron job.&lt;BR /&gt;&lt;BR /&gt;We are currently using the below script. If you can have better and easier suggestions, then it would be helpful.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;#&lt;BR /&gt;# this script should be run (via cron) daily to keep DMC log at a&lt;BR /&gt;# reasonable size&lt;BR /&gt;#&lt;BR /&gt;WHOAMI=/usr/bin/whoami&lt;BR /&gt;ECHO=/usr/bin/echo&lt;BR /&gt;CP=/usr/bin/cp&lt;BR /&gt;DATE=/usr/bin/date&lt;BR /&gt;CAT=/usr/bin/cat&lt;BR /&gt;ED=/usr/bin/ed&lt;BR /&gt;LOGGER=/usr/bin/logger&lt;BR /&gt;DMCLOGDIR=/var/opt/dmc/logs&lt;BR /&gt;DMCLOG=dmc.log&lt;BR /&gt;&lt;BR /&gt;#&lt;BR /&gt;# make sure script is running as root&lt;BR /&gt;#&lt;BR /&gt;if [ `$WHOAMI` != "root" ] ; then&lt;BR /&gt; $ECHO you must be root to run this script&lt;BR /&gt; exit&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;#&lt;BR /&gt;# copy the DMC log file&lt;BR /&gt;#&lt;BR /&gt;cd $DMCLOGDIR&lt;BR /&gt;$CP $DMCLOG ${DMCLOG}.Day`$DATE -u +%d`&lt;BR /&gt;&lt;BR /&gt;#&lt;BR /&gt;#&lt;BR /&gt;# truncate the DMC log file&lt;BR /&gt;#&lt;BR /&gt;$CAT - &amp;lt;&lt;EOF&gt;&lt;/EOF&gt;1,$ d&lt;BR /&gt;w&lt;BR /&gt;q&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;#&lt;BR /&gt;# put log entry in the syslog file&lt;BR /&gt;#&lt;BR /&gt;$LOGGER $DMCLOG truncated at `$DATE`&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Aug 2010 09:17:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251643#M471003</guid>
      <dc:creator>Robert Peregrin</dc:creator>
      <dc:date>2010-08-16T09:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251644#M471004</link>
      <description>Hi Robert:&lt;BR /&gt;&lt;BR /&gt;#&lt;BR /&gt;#&lt;BR /&gt;# truncate the DMC log file&lt;BR /&gt;#&lt;BR /&gt;&lt;BR /&gt;&amp;gt; $DMCLOG&lt;BR /&gt;&lt;BR /&gt;rgs,&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Aug 2010 09:26:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251644#M471004</guid>
      <dc:creator>rariasn</dc:creator>
      <dc:date>2010-08-16T09:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251645#M471005</link>
      <description>Note: I need to truncate the log file but it should still contain 1 month old data.</description>
      <pubDate>Mon, 16 Aug 2010 09:33:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251645#M471005</guid>
      <dc:creator>Robert Peregrin</dc:creator>
      <dc:date>2010-08-16T09:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251646#M471006</link>
      <description>Hi Rorbert:&lt;BR /&gt;&lt;BR /&gt;Sample scheduled script with cron:&lt;BR /&gt;&lt;BR /&gt;# cd /var/spool/cron/crontabs&lt;BR /&gt;&lt;BR /&gt;# cat root&lt;BR /&gt;&lt;BR /&gt;30 1 1 * * /tmp/test.sh #Test&lt;BR /&gt;&lt;BR /&gt;# ll root&lt;BR /&gt;&lt;BR /&gt;-rw-------   1 root  sys  30 Aug 16 12:43 root&lt;BR /&gt;&lt;BR /&gt; The entries in a crontab file are lines of six fields each.  The  fields are separated by spaces or tabs.  The lines have the following format:&lt;BR /&gt;&lt;BR /&gt;      minute  hour  monthday  month  weekday  command&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# crontab -l&lt;BR /&gt;&lt;BR /&gt;&lt;MAN crontab=""&gt;&lt;BR /&gt;&lt;BR /&gt;rgs,&lt;/MAN&gt;</description>
      <pubDate>Mon, 16 Aug 2010 09:47:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251646#M471006</guid>
      <dc:creator>rariasn</dc:creator>
      <dc:date>2010-08-16T09:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251647#M471007</link>
      <description>&amp;gt;it should still contain 1 month old data.&lt;BR /&gt;&lt;BR /&gt;What is the format of the file and what are the answers to my other questions?</description>
      <pubDate>Mon, 16 Aug 2010 11:03:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251647#M471007</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-08-16T11:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251648#M471008</link>
      <description>The file is called dmc.log. Its an application specific log file in text format.&lt;BR /&gt;&lt;BR /&gt;Sample date string in the file is  "Sat Aug 14 18:42:19 2010."&lt;BR /&gt;&lt;BR /&gt;Yes, I need to keep exactly 1 month old data (number of days depends on the month as some months have 30 days, some have 31 and February have 29 or 28 days) in the file. &lt;BR /&gt;&lt;BR /&gt;It doesn't matter when I run the script for as long as I will be able to truncate the file with 1 month old data kept.</description>
      <pubDate>Mon, 16 Aug 2010 11:17:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251648#M471008</guid>
      <dc:creator>Robert Peregrin</dc:creator>
      <dc:date>2010-08-16T11:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251649#M471009</link>
      <description>&lt;!--!*#--&gt;This should work for selecting the lines from the log file.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl -w&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;&lt;BR /&gt;my @prev_months= qw(Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);&lt;BR /&gt;&lt;BR /&gt;my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);&lt;BR /&gt;&lt;BR /&gt;my $fh;&lt;BR /&gt;open($fh,$ARGV[0]);&lt;BR /&gt;my $line;&lt;BR /&gt;my @parts;&lt;BR /&gt;&lt;BR /&gt;while ($line = &amp;lt;$fh&amp;gt;) {&lt;BR /&gt;        @parts=split(' +',$line);&lt;BR /&gt;        if      (($parts[1] eq $prev_months[$mon]) &amp;amp;&amp;amp; ($parts[2] &amp;gt; $mday)) {&lt;BR /&gt;                print $line;&lt;BR /&gt;        }&lt;BR /&gt;        if      (($parts[1] eq $prev_months[($mon+1)]) &amp;amp;&amp;amp; ($parts[2] &amp;lt;= $mday)) {&lt;BR /&gt;                print $line;&lt;BR /&gt;        }&lt;BR /&gt;}&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Aug 2010 11:52:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251649#M471009</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2010-08-16T11:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251650#M471010</link>
      <description>&lt;!--!*#--&gt;&amp;gt;I need to keep exactly 1 month old data (number of days depends on the month as some months have 30 days, some have 31 and February have 29 or 28 days) in the file.&lt;BR /&gt;&lt;BR /&gt;The number of days in a month is useless unless you are at the end of the month.  If you are in the middle, what does it mean?&lt;BR /&gt;&lt;BR /&gt;&amp;gt;It doesn't matter when I run the script for as long as I will be able to truncate the file with 1 month old data kept.&lt;BR /&gt;&lt;BR /&gt;I assume we can make the assumption that if today is Aug 16, you want the info from July 16 to today?&lt;BR /&gt;&lt;BR /&gt;You could make an awk script to scan every record for these fields:&lt;BR /&gt;Sat Aug 14 18:42:19 2010&lt;BR /&gt;&lt;BR /&gt;if ($2 == prevmon &amp;amp;&amp;amp; $3 &amp;gt;= currday &amp;amp;&amp;amp; $5 &amp;gt;= prevyear ||&lt;BR /&gt;    $2 == currmon &amp;amp;&amp;amp; $5 == curryear) copy=1&lt;BR /&gt;&lt;BR /&gt;You would have to do date arithmetic to figure out what the previous month's name and year is.  The current month, day and year can be gotten from date(1).&lt;BR /&gt;&lt;BR /&gt;Once "copy" is set, just read &amp;amp; print to the end of the file.</description>
      <pubDate>Mon, 16 Aug 2010 11:55:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251650#M471010</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-08-16T11:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251651#M471011</link>
      <description>Thanks Guys. Your suggestions are good but we chose to retain the running script we are using.</description>
      <pubDate>Wed, 18 Aug 2010 10:33:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251651#M471011</guid>
      <dc:creator>Robert Peregrin</dc:creator>
      <dc:date>2010-08-18T10:33:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to truncate Log file to contain one month data only</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251652#M471012</link>
      <description>I have already found an alternative solution to my question.</description>
      <pubDate>Wed, 18 Aug 2010 10:41:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-truncate-log-file-to-contain-one-month-data-only/m-p/5251652#M471012</guid>
      <dc:creator>Robert Peregrin</dc:creator>
      <dc:date>2010-08-18T10:41:20Z</dc:date>
    </item>
  </channel>
</rss>

