Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Inserting Date&Time Stamp In Existing Log File Post 100122 by amitkhiare on Friday 24th of February 2006 03:01:44 AM
Old 02-24-2006
Quote:
Originally Posted by shephardfamily
I understand that I can write a shell script but what is the syntax to put the time and date in a file and be able to grep all lines below that particular time that I inserted when I am comparing what was there lets say 24 hours ago then pull only those lines. Also, I would like to know how to grep for those lines pulling only the errors generated and place them into a email? Smilie

This is the structure that I have:

#!/bin/sh
# Every 6 hours

# Get all lines from the arlog based on the last PREVIOUS_TIME date and time.

PREVIOUS_TIME='DATE AND TIME: `date`' in the arlog

NEW_TIME='TODAYS DATE AND TIME: `date` ' in the arlog

#LIST OF ERRORS THAT WILL BE SEARCHED.

ERRMSG='CHECKING FOR ERRORS IN ARLOG: ERROR 9999'
ERRMSG1='0403-031 The fork function failed. There is not enough memory available.'
ERRMSG2='Login failed.'
ERRMSG3='ftp: connect: Connection timed out.'
ERRMSG4='ftp: connect: Connection refused.'
ERRMSG5='endeavour: unknown host or invalid literal address.'
ERRMSG6='ftp: Unknown host diamprodf0'
ERRMSG7='ORA-06508: PL/SQL: could not find program unit being called.'
ERRMSG8='ORA-01034: ORACLE not available.'
ERRMSG9='ORA-27101: shared memory realm does not exist.'
ERRMSG10='ORA-01005: null password given; logon denied.'
ERRMSG11='SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL.'
ERRMSG12='ORA-04068: existing state of packages has been discarded.'
ERRMSG13='ORA-04063: package body "FININTER.HAP_CUSTOMERS_INTERFACE" has errors.'
ERRMSG14='ORA-06512: IN LINE ERROR.'
ERRMSG15='ORA-01005: null password given.'

grep 'DATE STAMP: $PREVIOUS_TIME ' arlog >> TEMP_ARLOG.log

if $NEW_TIME in the arlog NOT EQUAL $PREVIOUS_TIME in arlog
then
egrep "(${ERRMSG} | ${ERRMSG1} | ${ERRMSG2} |........) from arlog.
if NO ERRORS EXIST
then
put $NEW_TIME 'No Errors To Date and time" >> arlog
else
mailx -s '$ERRORS `date` to [FMT] with message describing error or errors.
grep 'LAST TIME TRANSMISSION:' $PREVIOUS_TIME >> arlog
fi
fi

Now how do I put the code into a structure that will generate what I want to do above? Smilie
HI,

Use this command for current date and time stamp

`date '+%m%d%y%H%M'`

I have ? for you what do you mean by PREVIOUS_TIME. As i understand it would be yesterday's date and time right. If not just let me know what value will be stored in PREVIOUS_TIME.

Hope i have answered some part of your query.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

File date and time stamp

I have to capture the creation date and time stamp for a file. The ls command doesn't list all the required information. I need year, month, day, hour, minute and second. Any ideas... (1 Reply)
Discussion started by: Xenon
1 Replies

2. Shell Programming and Scripting

Extract info from log file and compute using time date stamp

Looking for a shell script or a simple perl script . I am new to scripting and not very good at it . I have 2 directories . One of them holds a text file with list of files in it and the second one is a daily log which shows the file completion time. I need to co-relate both and make a report. ... (0 Replies)
Discussion started by: breez_drew
0 Replies

3. Linux

rename files in a folder with date&time stamp

Hi, I want to rename all the files (more than 100 files) in a fodler to another folder with date&time stamp. foe eg, file1.dat file2.dat file3.dat .. to be renamed as file1100629_16_30_15.txt (yy-mon-dd_hh_mi_ss) file1100629_16_30_16.txt .. so on (2 Replies)
Discussion started by: feroz
2 Replies

4. UNIX for Dummies Questions & Answers

ls -ltr for a future date/time stamp file

Hi When i do ls -ltr <file1> then it shows me the date and time of the file if - for whatever reason file has future date/time stamp then ls -ltr is not showing the time, it just shows only date part ... even if time is ahead by 2 hr than current time. suppose a file was copied from INDIA... (3 Replies)
Discussion started by: reldb
3 Replies

5. Shell Programming and Scripting

Set date and time stamp of one file to another

Hi I use "touch -t xxxxxxxx" command to set date/time stamp of a file. My requirement is to read the date/time stamp of a file and apply it to another file. Is there anyway to do it simple instead of manually taking date/stamp of first file? TIA Prvn (2 Replies)
Discussion started by: prvnrk
2 Replies

6. Shell Programming and Scripting

If(Condition) Rename a file with (Date+Time) Stamp

Hi! Please see our current script: #!/usr/bin/ksh if (egrep "This string is found in the log" /a01/bpm.log) then mailx -s "Error from log" me@email.com, him@email.com </a01/bpm.log fi To the above existing script, we need to add the following change: 1) After finding the string,... (7 Replies)
Discussion started by: atechcorp
7 Replies

7. Shell Programming and Scripting

How to extract latest file by looking at date time stamp from a directory?

hi, i have a Archive directory in which files are archived or stored with date and time stamp to prevent over writing. example: there are 5 files s1.txt s2.txt s3.txt s4.txt s5.txt while moving these files to archive directory, date and time stamp is added. of format `date... (9 Replies)
Discussion started by: Little
9 Replies

8. Shell Programming and Scripting

Shell Script | Parse log file after a given date and time stamp

I am developing one script which will take log file name, output file name, date, hour and minute as an argument and based on these inputs, the script will scan and capture all the error(s) that have been triggered from a given time. Example: script should capture all the error after 13:50 on Jan... (2 Replies)
Discussion started by: ROMA3
2 Replies

9. Shell Programming and Scripting

Change date time stamp of existing file

I have a file hello.txt which was created today (today's date timestamp) I wish to change its date timestamp (access, modified, created) to 1 week old i.e one week from now. uname -a SunOS mymac 5.11 11.2 sun4v sparc sun4v Can you please suggest a easy way to do that ? (12 Replies)
Discussion started by: mohtashims
12 Replies

10. Shell Programming and Scripting

Add current time stamp column in existing csv file

Hi , I want to add a new column 'current_time stamp' in my existing csv file with current time stamp for all the records.I tried something this but this is printing 0 with date & time and printed date one line above header.Please help awk -F "," 'BEGIN{ OFS="," } {$6=system("date... (5 Replies)
Discussion started by: netdbaind
5 Replies
Date::Parse(3pm)					User Contributed Perl Documentation					  Date::Parse(3pm)

NAME
Date::Parse - Parse date strings into time values SYNOPSIS
use Date::Parse; $time = str2time($date); ($ss,$mm,$hh,$day,$month,$year,$zone) = strptime($date); DESCRIPTION
"Date::Parse" provides two routines for parsing date strings into time values. str2time(DATE [, ZONE]) "str2time" parses "DATE" and returns a unix time value, or undef upon failure. "ZONE", if given, specifies the timezone to assume when parsing if the date string does not specify a timezone. strptime(DATE [, ZONE]) "strptime" takes the same arguments as str2time but returns an array of values "($ss,$mm,$hh,$day,$month,$year,$zone)". Elements are only defined if they could be extracted from the date string. The $zone element is the timezone offset in seconds from GMT. An empty array is returned upon failure. MULTI-LANGUAGE SUPPORT Date::Parse is capable of parsing dates in several languages, these include English, French, German and Italian. $lang = Date::Language->new('German'); $lang->str2time("25 Jun 1996 21:09:55 +0100"); EXAMPLE DATES
Below is a sample list of dates that are known to be parsable with Date::Parse 1995:01:24T09:08:17.1823213 ISO-8601 1995-01-24T09:08:17.1823213 Wed, 16 Jun 94 07:29:35 CST Comma and day name are optional Thu, 13 Oct 94 10:13:13 -0700 Wed, 9 Nov 1994 09:50:32 -0500 (EST) Text in ()'s will be ignored. 21 dec 17:05 Will be parsed in the current time zone 21-dec 17:05 21/dec 17:05 21/dec/93 17:05 1999 10:02:18 "GMT" 16 Nov 94 22:28:20 PST LIMITATION
Date::Parse uses Time::Local internally, so is limited to only parsing dates which result in valid values for Time::Local::timelocal. This generally means dates between 1901-12-17 00:00:00 GMT and 2038-01-16 23:59:59 GMT BUGS
When both the month and the date are specified in the date as numbers they are always parsed assuming that the month number comes before the date. This is the usual format used in American dates. The reason why it is like this and not dynamic is that it must be deterministic. Several people have suggested using the current locale, but this will not work as the date being parsed may not be in the format of the current locale. My plans to address this, which will be in a future release, is to allow the programmer to state what order they want these values parsed in. AUTHOR
Graham Barr <gbarr@pobox.com> COPYRIGHT
Copyright (c) 1995-2009 Graham Barr. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2010-07-28 Date::Parse(3pm)
All times are GMT -4. The time now is 12:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy