Sponsored Content
Full Discussion: Log rotation script
Top Forums Shell Programming and Scripting Log rotation script Post 302898760 by e_mikey_2000 on Wednesday 23rd of April 2014 05:52:52 PM
Old 04-23-2014
Log rotation script

I have an application that rotate its log once it reaches 100mb and it keeps a total of 24 logs. I am trying to write a script to run daily to tar up the previous day logs files and move them to a different directory. here is a long listing of the logs in the directory:
Code:
-rw-r--r--   1 user1     user1     100000150 Apr 19 10:46 log.24
-rw-r--r--   1 user1     user1     100004207 Apr 19 14:21 log.23
-rw-r--r--   1 user1     user1     100004463 Apr 19 18:22 log.22
-rw-r--r--   1 user1     user1     100003277 Apr 19 22:33 log.21
-rw-r--r--   1 user1     user1     100000833 Apr 20 03:03 log.20
-rw-r--r--   1 user1     user1     100002192 Apr 20 09:07 log.19
-rw-r--r--   1 user1     user1     100004056 Apr 20 12:45 log.18
-rw-r--r--   1 user1     user1     100000851 Apr 20 16:16 log.17
-rw-r--r--   1 user1     user1     100001805 Apr 20 20:21 log.16
-rw-r--r--   1 user1     user1     100003432 Apr 21 00:50 log.15
-rw-r--r--   1 user1     user1     100002232 Apr 21 06:23 log.14
-rw-r--r--   1 user1     user1     100004079 Apr 21 10:38 log.13
-rw-r--r--   1 user1     user1     100004782 Apr 21 14:13 log.12
-rw-r--r--   1 user1     user1     100000374 Apr 21 17:50 log.11
-rw-r--r--   1 user1     user1     100004002 Apr 21 21:29 log.10
-rw-r--r--   1 user1     user1     100001480 Apr 22 02:15 log.09
-rw-r--r--   1 user1     user1     100002608 Apr 22 07:12 log.08
-rw-r--r--   1 user1     user1     100000332 Apr 22 11:24 log.07
-rw-r--r--   1 user1     user1     100002060 Apr 22 15:12 log.06
-rw-r--r--   1 user1     user1     100000087 Apr 22 18:45 log.05
-rw-r--r--   1 user1     user1     100000197 Apr 22 22:41 log.04
-rw-r--r--   1 user1     user1     100000436 Apr 23 03:26 log.03
-rw-r--r--   1 user1     user1     100004005 Apr 23 08:54 log.02
-rw-r--r--   1 user1     user1     100003351 Apr 23 12:29 log.01
-rw-r--r--   1 user1     user1     55085889 Apr 23 14:20 log

for example, if we run the script on the 23rd, it should tar up all the logs for the 22nd ( log.04-log.09) and move then to a different directory.

If I try to use the find command with the mtime option, I does not provide the all the logs for the previous day.

Your help is very much appreciated.

Last edited by e_mikey_2000; 04-23-2014 at 07:00 PM.. Reason: code tag
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Log Rotation Tool/Script

Hello all Does anyone has an intersting script or a good freeware tool for log rotation that is good for Unix and Linux as well ? My thanks in advance (4 Replies)
Discussion started by: yelalouf
4 Replies

2. HP-UX

Log rotation on HP-UX

Can anyone post a sample log rotate and archive configuration on HP-UX? I really don't know how to do that... :( (3 Replies)
Discussion started by: untamed
3 Replies

3. Shell Programming and Scripting

log rotation

Hello all. Due to some reason I can not use HUP to rotate needed log files. So I use the standard method: cp $file $file.1 cat /dev/null > $file But if Java application in this time writing the output to $file, in the beginning of it appears many "^@^@^@^@^@^@". How to avoid it? Or how... (6 Replies)
Discussion started by: mirusnet
6 Replies

4. Shell Programming and Scripting

Log rotation script

I have the below script to help with disk space cleanup that finds logs older than a specified number of days (say 10 days). I need it to grab "active" logs as well. Problem is an "active log" will not get archived unless I put in 0 days which I don't want to do, I need to leave the past 10 days,... (2 Replies)
Discussion started by: theninja
2 Replies

5. Shell Programming and Scripting

Log rotation issue with script

I have application which to the heavy stdout and I have diverted the stdout to log file. this log file is writing very heavily and we have a script which rotates the logs. logic for rotation is smthing like cp logfile logfile.1 cat /dev/null > logfile this logic was working fine till we... (3 Replies)
Discussion started by: navinmistry
3 Replies

6. Solaris

Solaris log rotation

HI, What is log rotation in Solaris ? What are the essential steps to perform log rotation in Solaris? (1 Reply)
Discussion started by: Revathi@1
1 Replies

7. Solaris

Log rotation, twice

hi folk, need advise regarding the log rotation, i have the logadm set at 30 2 * * * /usr/sbin/logadm so it supposed to rotate once per day, but now it rotated twice! but someone my log will rotate at 2:30 AM, but then another 2 hours later, it creates a new and rotate a new log again,... (2 Replies)
Discussion started by: dehetoxic
2 Replies

8. UNIX for Dummies Questions & Answers

Log Rotation

Hi Guys, Good morning, I just want to know and collect ideas on this one. Regarding rotation of logs as I've observed it's not consistently functioning. I have a server with 8 Partitions, each partition has a dedicated directory for the logs that is needed and I set it every 5mins (300secs) the... (1 Reply)
Discussion started by: rymnd_12345
1 Replies

9. Solaris

Log rotation

Hi All! I seem to have a problem with log rotation, unless I am doing something wrong, I have type the following command for testing purposes to see if the -s option works but he did not: logadm -w /var/adm/messages -C 8 -c -s 512k -t '/var/adm/messages.$n' -z 1 the file is now at this... (7 Replies)
Discussion started by: fretagi
7 Replies

10. OS X (Apple)

Mavericks log rotation

In Mavericks, Apple has apparently moved control of log rotation to ASL. There's a 'ttl' value to determine how long log files will stick around for. I can compress them, change the way they're named, limit them by size, etc. But the one thing I cannot find is how to NOT keep one log file per... (0 Replies)
Discussion started by: jnojr
0 Replies
ROTATELOGS(8)							    rotatelogs							     ROTATELOGS(8)

NAME
rotatelogs - Piped logging program to rotate Apache logs SYNOPSIS
rotatelogs [ -l ] [ -f ] logfile rotationtime|filesizeM [ offset ] SUMMARY
rotatelogs is a simple program for use in conjunction with Apache's piped logfile feature. It supports rotation based on a time interval or maximum size of the log. OPTIONS
-l Causes the use of local time rather than GMT as the base for the interval or for strftime(3) formatting with size-based rotation. Note that using -l in an environment which changes the GMT offset (such as for BST or DST) can lead to unpredictable results! -f Causes the logfile to be opened immediately, as soon as rotatelogs starts, instead of waiting for the first logfile entry to be read (for non-busy sites, there may be a substantial delay between when the server is started and when the first request is handled, meaning that the associated logfile does not "exist" until then, which causes problems from some automated logging tools). Available in version 2.2.9 and later. logfile rotationtime The time between log file rotations in seconds. The rotation occurs at the beginning of this interval. For example, if the rotation time is 3600, the log file will be rotated at the beginning of every hour; if the rotation time is 86400, the log file will be rotated every night at midnight. (If no data is logged during an interval, no file will be created.) filesizeM The maximum file size in megabytes followed by the letter M to specify size rather than time. offset The number of minutes offset from UTC. If omitted, zero is assumed and UTC is used. For example, to use local time in the zone UTC -5 hours, specify a value of -300 for this argument. In most cases, -l should be used instead of specifying an offset. EXAMPLES
CustomLog "|bin/rotatelogs /var/logs/logfile 86400" common This creates the files /var/logs/logfile.nnnn where nnnn is the system time at which the log nominally starts (this time will always be a multiple of the rotation time, so you can synchronize cron scripts with it). At the end of each rotation time (here after 24 hours) a new log is started. CustomLog "|bin/rotatelogs -l /var/logs/logfile.%Y.%m.%d 86400" common This creates the files /var/logs/logfile.yyyy.mm.dd where yyyy is the year, mm is the month, and dd is the day of the month. Logging will switch to a new file every day at midnight, local time. CustomLog "|bin/rotatelogs /var/logs/logfile 5M" common This configuration will rotate the logfile whenever it reaches a size of 5 megabytes. ErrorLog "|bin/rotatelogs /var/logs/errorlog.%Y-%m-%d-%H_%M_%S 5M" This configuration will rotate the error logfile whenever it reaches a size of 5 megabytes, and the suffix to the logfile name will be cre- ated of the form errorlog.YYYY-mm-dd-HH_MM_SS. PORTABILITY
The following logfile format string substitutions should be supported by all strftime(3) implementations, see the strftime(3) man page for library-specific extensions. o %A - full weekday name (localized) o %a - 3-character weekday name (localized) o %B - full month name (localized) o %b - 3-character month name (localized) o %c - date and time (localized) o %d - 2-digit day of month o %H - 2-digit hour (24 hour clock) o %I - 2-digit hour (12 hour clock) o %j - 3-digit day of year o %M - 2-digit minute o %m - 2-digit month o %p - am/pm of 12 hour clock (localized) o %S - 2-digit second o %U - 2-digit week of year (Sunday first day of week) o %W - 2-digit week of year (Monday first day of week) o %w - 1-digit weekday (Sunday first day of week) o %X - time (localized) o %x - date (localized) o %Y - 4-digit year o %y - 2-digit year o %Z - time zone name o %% - literal `%' Apache HTTP Server 2010-11-06 ROTATELOGS(8)
All times are GMT -4. The time now is 04:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy