No announcement yet.

Simple Log Rotation Script

  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple Log Rotation Script

    Attached is a simple Log Rotation script I put together to rename the log file to a date based filename and move it to an archive directory.

    The name for a log archived off on 01/22/2002 would be hs020122.log. It has an option to extend the filename to include the time as well. I use that when I run the script manually or via a web page so I don't overwrite any existing logs that may have been archived on the same date.

    My setup has the script run nightly at midnight.
    Prior to running the script, create a directory called OldLogs in your HomeSeer directory.

    [This message was edited by Rob Brun on Thursday, 24 January 2002 at 08:09 AM.]
    Attached Files

  • #2
    Hi Rob,

    Script works great! Thanks for posting it.

    HS 1990 Devices 1172 Events
    Z-Wave 126 Nodes on one Z-Net


    • #3
      I am getting a error...

      22.January.2002 10:51:20 PM~!~Info~!~ Script Error, File: rotate_log.txt: 76:File not found in line 14

      Eric Trudeau
      | E-mail | HomeSeer Status |


      • #4
        Did you create the OldLogs directory in your HomeSeer directory?


        • #5
          Very Nice!!!


          MSI Cubi Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2201 Mhz, 2 Core(s), 4 Logical Processor(s) 16GB DDRl RAM

          Enabled Plug-Ins
          BLRussound, BLSpeech, HSTouch Server, JowiHue, MyQ, Nest, Rain8, Squeezebox, Ultra1Wire3, UltraGCIR3, Vista Alarm, X10,Z-Wave


          • #6
            Just a suggestion, how about a more detailed installation text. I know that some (like myself)muddle thru the script and eventually get things working. Thank you for the great work.



            • #7
              <BLOCKQUOTE><font size="-1">quote:</font><HR>Originally posted by Rob Brun:
              Did you create the OldLogs directory in your HomeSeer directory?<HR></BLOCKQUOTE>

              ahh thanks!

              How would I modify the file to have the file name be hs(day)(month)(year)?

              as in hs230102.log


              Eric Trudeau
              | E-mail | HomeSeer Status |


              • #8
                I could have been more discript with the install text, at the time I just threw it up there because I saw that someone was wanting something like that. Sorry about that guys.

                To change the timestamp order that is used in the name, change the order of the blocks between lines 41 through 49. To get day, month, year it would look like this:

                str = pre
                strTemp = DatePart("d",strDate)
                if (0 + strTemp) &lt; 10 then strTemp = "0" & strTemp
                str = str & strTemp

                strTemp = DatePart("m",strDate)
                if (0 + strTemp) &lt; 10 then strTemp = "0" & strTemp
                str = str & strTemp

                str = str & Right(DatePart("yyyy",strDate),2)

                Here's a old IT guy tip as to why I did year, month, day.... after the first year when you sort by filename in the directory you want to keep your years together rather than your days or months. Remember how Windows sorts files, it will be left to right.


                • #9
                  Thanks Rob

                  I dont really worry about the date thing. I would never see something like that. I can hardly go 2 weeks without formatting harddrives and starting over. I like things to run at top speed. And formatting does that. [img]/infopop/emoticons/icon_smile.gif[/img]

                  Eric Trudeau
                  | E-mail | HomeSeer Status |


                  • #10
                    If anyone is interested, I created a set of log file rotate and archive scripts a while back. The archive script uses your choice of a command-line compression util to periodically "zip" up all logs into a date-named archive file for storage. Also works with HSP logs.

                    I run my log rotator each night, and the archive script on the 1st of each month. The archive script compresses all of the previous month's logs, as rotated nightly to the date-named log file, into a nice compact archive. Save your disk space!

                    They should be available on the Home Automation section of my site, - click the Gordon's Site link on the opening page and then the Home Automation button.

                    - huggy
                    | - Gordon

                    "I'm a Man, but I can change, if I have to, I guess." - Man's Prayer, Possum Lodge, The Red Green Show
           - -


                    • #11
                      Thanks for the script, working great!

                      For some reason I can't get to your site, perhaps it's down. I'd like to take a look at your monthly zip script.


                      • #12
                        ...why are we backing these up? I seem to back them up and never, I mean never, go back and use them for anything. What do you guys do with your log files?



                        • #13
                          I guess it's just like anything else. YOU JUST NEVER KNOW... [img]/infopop/emoticons/icon_rolleyes.gif[/img]



                          • #14
                            I need a little bit of clarification as to what is happening here. I've implemented your script setting up an event which triggers daily at 11:59 pm. It creates the new dated log file and copies the log over. The ah.log file gets cleared out and starts with that new days log activities....all of this what I would have expected.

                            However, the HS log (viewed by clicking the log button on left view pane) does not show just that day's shows the whole log from the last time HS was started (or I had hit the clear log button). I would have expected that it would show the same thing as the ah.log file. I've gone back out to an event and status view and then back into log view....but it still shows the complete older multiple day log file.

                            Is this working as designed, or did I miss a step in installation some how? After creating and copying over the new daily log file, should the script issue a clear HS log command of some sort? If not, how do you clear the HS log to get rid of the prior days activities, without loosing some of the current day activities?

                            standard HS build 10, w/2000


                            • #15
                              The scripts are only working with the log file on disk, but the display log remains untouched. This can actually be very convenient.

                              Nucleus Home Automation
                              News, support, and updates for Rover, Network Monitor, TimeIcons, and more