Sponsored Content
Top Forums Shell Programming and Scripting Retrieve logs for previous 4 hours Post 302488617 by pravin27 on Tuesday 18th of January 2011 02:00:33 AM
Old 01-18-2011
Try this,


Code:
#!/usr/bin/perl
@abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
($year,$month,$day,$hr)=(localtime(time-4 * 60 * 60))[5,4,3,2];
$year+=1900;
$month++;
print "$day\\/$abbr[$month]\\/$year:$hr\n";

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

search and retrieve previous line in file

I've got a file with the following layout: #STMP FSgroup filename /filesysname1 filestatus 2 #STMP FSstatus filename /filesysname1 ratio 30 #STMP FSgroup filename ... (2 Replies)
Discussion started by: paulsew
2 Replies

2. UNIX for Dummies Questions & Answers

Delete logs every 3 hours

Hi, I want to setup a cronjob that will delete logs every 2 hours. I have script that delete logs per day. but logging is too big and i want to run a conjob that will delete every 2 hours. this is my current command but it deletes on a per day basis. find . -name "*.log*" -o -name... (3 Replies)
Discussion started by: tungaw2004
3 Replies

3. Shell Programming and Scripting

Grep yesterday logs from weblogic logs

Hi, I am trying to write a script which would go search and get the info from the logs based on yesterday timestamp and write yesterday logs in new file. The log file format is as follows: """"""""""""""""""""""""""... (3 Replies)
Discussion started by: harish.parker
3 Replies

4. Shell Programming and Scripting

how to list files between last 6 hours to 3 hours

Hi Frens, I want to list some files from a directory, which contains "DONE" in their name, i am receiving files every minute. In this i want to list all the files which are newer than 6 hours but older than 3 hours, of current time i dont want my list to contain the latest files which are ... (4 Replies)
Discussion started by: Prat007
4 Replies

5. Shell Programming and Scripting

Retrieve logs for last 4 hours

Our log file looks like this: 2010-11-18 00:57:01,698 ERROR Shipment Error Log:Error Details - Account Id:3962, PO:2710015, Line:2, File:221112901, Version:V1, Desc:Order cannot not be shipped as there are no line items in New state 2010-11-18 14:59:39,960 ERROR... (11 Replies)
Discussion started by: Deepthz
11 Replies

6. Shell Programming and Scripting

Command to clear logs for every 6 hours in solaris

Hi Folks, I need to remove log files for six hours on Solaris. before i used to do for every 24 hours below is the code for 1 day older log files, now i tried using -mmin +360 but it says command not found. Can someone please help me out!!! part of the code: LOG_FILE=`find /home/Logdir... (1 Reply)
Discussion started by: Sendhil.Kumaran
1 Replies

7. Shell Programming and Scripting

Retrieve logs generated in last 10 mins from a log file using 'grep' command

HI All, I have a log file where the logs will be in the format as given below: 2011-05-25 02:32:51 INFO PROCESS STARTING 2011-05-25 02:32:52 INFO PROCESS STARTED . . . I want to retrieve only the logs which are less than 5 mins older than current time using grep... (3 Replies)
Discussion started by: rvhg16
3 Replies

8. UNIX for Dummies Questions & Answers

Removing the logs of previous date

Hi folks, Please advise there is directory named logs and which there are several logs are there with the name appended by date , I can take out the latest one through cd /var/log ls -ltr but please suggest the command through which I can remove the logs of all the previous dats , the... (2 Replies)
Discussion started by: SankalpS
2 Replies

9. Shell Programming and Scripting

Remove previous line if next & previous lines have same 4th character.

I want to remove commands having no output. In below text file. bash-3.2$ cat abc_do_it.txt grpg10so>show trunk group all status grpg11so>show trunk group all status grpg12so>show trunk group all status GCPKNYAIGT73IMO 1440 1345 0 0 94 0 0 INSERVICE 93% 0%... (4 Replies)
Discussion started by: Raza Ali
4 Replies

10. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies
cronolog(1m)															      cronolog(1m)

NAME
cronolog - write log messages to log files named according to a template SYNOPSIS
cronolog [OPTION]... template DESCRIPTION
cronolog is a simple program that reads log messages from its input and writes them to a set of output files, the names of which are con- structed using template and the current date and time. The template uses the same format specifiers as the Unix date(1) command (which are the same as the standard C strftime library function). Before writing a message cronolog checks the time to see whether the current log file is still valid and if not it closes the current file, expands the template using the current date and time to generate a new file name, opens the new file (creating missing directories on the path of the new log file as needed unless the program is compiled with -DDONT_CREATE_SUBDIRS) and calculates the time at which the new file will become invalid. cronolog is intended to be used in conjunction with a Web server, such as Apache to split the access log into daily or monthly logs. For example the Apache configuration directives: TransferLog "|/usr/bin/cronolog /www/logs/%Y/%m/%d/access.log" ErrorLog "|/usr/bin/cronolog /www/logs/%Y/%m/%d/errors.log" would instruct Apache to pipe its access and error log messages into separate copies of cronolog, which would create new log files each day in a directory hierarchy structured by date, i.e. on 31 December 1996 messages would be written to /www/logs/1996/12/31/access.log /www/logs/1996/12/31/errors.log after midnight the files /www/logs/1997/01/01/access.log /www/logs/1997/01/01/errors.log would be used, with the directories 1997, 1997/01 and 1997/01/01 being created if they did not already exist. (Note that prior to version 1.2 Apache did not allow a program to be specified as the argument of the ErrorLog directive.) Options cronolog accepts the following options and arguments: -H NAME --hardlink=NAME maintain a hard link from NAME to the current log file. -S NAME --symlink=NAME -l NAME --link=NAME maintain a symbolic link from NAME to the current log file. -P NAME --prev-simlink=NAME maintain a symbolic link from NAME to the previous log file. Requires that the --symlink option is specified, as cronolog renames the current link to the name specified for the previous link. -h --help print a help message and then exit. -p PERIOD --period=PERIOD specifies the period explicitly as an optional digit string followed by one of units: seconds, minutes, hours, days, weeks or months. The count cannot be greater than the number of units in the next larger unit, i.e. you cannot specify "120 minutes", and for seconds, minutes and hours the count must be a factor of the next higher unit, i.e you can specify 1, 2, 3, 4, 5, 6, 10, 15, 20 or 30 minutes but not say 7 minutes. -d PERIOD --delay=PERIOD specifies the delay from the start of the period before the log file is rolled over. For example specifying (explicitly or implic- itly) a period of 15 minutes and a delay of 5 minutes results in the log files being rotated at five past, twenty past, twentyfive to and ten to each hour. The delay cannot be longer than the period. -o --once-only create single output log from template, which is not rotated. -x FILE --debug=FILE write debug messages to FILE or to the standard error stream if FILE is "-". (See the README file for more details.) -s TIME --start-time=TIME pretend that the starting time is TIME (for debugging purposes). TIME should be something like DD MONTH YYYY HH:MM:SS (the day and month are reversed if the american option is specified). If the seconds are omitted then they are taken as zero and if the hours and minutes are omitted then the time of day is taken as 00:00:00 (i.e. midnight). The day, month and year can be separated by spa- ces, hyphens (-) or solidi (/). -a --american Interprete the date part of the starting time the American way (month then day). -e --european Interprete the date part of the starting time the European way (day then month). This is the default. -v --version print version information and exit. Template format Each character in the template represents a character in the expanded filename, except for date and time format specifiers, which are replaced by their expansion. Format specifiers consist of a `%' followed by one of the following characters: % a literal % character n a new-line character t a horizontal tab character Time fields: H hour (00..23) I hour (01..12) p the locale's AM or PM indicator M minute (00..59) S second (00..61, which allows for leap seconds) X the locale's time representation (e.g.: "15:12:47") Z time zone (e.g. GMT), or nothing if the time zone cannot be determined Date fields: a the locale's abbreviated weekday name (e.g.: Sun..Sat) A the locale's full weekday name (e.g.: Sunday .. Saturday) b the locale's abbreviated month name (e.g.: Jan .. Dec) B the locale's full month name, (e.g.: January .. December) c the locale's date and time (e.g.: "Sun Dec 15 14:12:47 GMT 1996") d day of month (01 .. 31) j day of year (001 .. 366) m month (01 .. 12) U week of the year with Sunday as first day of week (00..53, where week 1 is the week containing the first Sunday of the year) W week of the year with Monday as first day of week (00..53, where week 1 is the week containing the first Monday of the year) w day of week (0 .. 6, where 0 corresponds to Sunday) x locale's date representation (e.g. today in April in Britain: "13/04/97") y year without the century (00 .. 99) Y year with the century (1970 .. 2038) Other specifiers may be available depending on the C library's implementation of the strftime function. SEE ALSO
apache(1m) date(1) strftime(3) environ(5) More information and the latest version of cronolog can be obtained from http://www.ford-mason.co.uk/resources/cronolog/ If you have any suggestions, bug reports, fixes, or enhancements, please mail them to the author. More about Apache Documentation for the Apache http server is available from http://www.apache.org FUTURE DIRECTIONS
The functionality of cronolog could be built into Apache, thus saving the overhead of having a process per log stream and that of transfer- ring data from the server process to the cronolog process. The main complication is handling the case where multiple log streams are writ- ten to the same file (template), for example where different virtual servers write to the same set of log files. AUTHOR
Andrew Ford <A.Ford@ford-mason.co.uk> cronolog is based on a program called rotatelogs by Ben Laurie, which is packaged with the Apache web server. The symbolic link option was suggested by Juergen Lesny. March 1998 cronolog(1m)
All times are GMT -4. The time now is 08:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy