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
Email::Date(3pm)					User Contributed Perl Documentation					  Email::Date(3pm)

NAME
Email::Date - Find and Format Date Headers SYNOPSIS
use Email::Date; my $email = join '', <>; my $date = find_date($email); print $date->ymd; my $header = format_date($date->epoch); Email::Simple->create( header => [ Date => $header, ], body => '...', ); DESCRIPTION
RFC 2822 defines the "Date:" header. It declares the header a required part of an email message. The syntax for date headers is clearly laid out. Stil, even a perfectly planned world has storms. The truth is, many programs get it wrong. Very wrong. Or, they don't include a "Date:" header at all. This often forces you to look elsewhere for the date, and hoping to find something. For this reason, the tedious process of looking for a valid date has been encapsulated in this software. Further, the process of creating RFC compliant date strings is also found in this software. FUNCTIONS find_date my $time_piece = find_date $email; "find_date" accepts an email message in any format Email::Abstract can understand. It looks through the email message and finds a date, converting it to a Time::Piece object. If it can't find a date, it returns false. "find_date" is exported by default. format_date my $date = format_date; # now my $date = format_date( time - 60*60 ); # one hour ago "format_date" accepts an epoch value, such as the one returned by "time". It returns a string representing the date and time of the input, as specified in RFC 2822. If no input value is provided, the current value of "time" is used. "format_date" is exported by default. format_gmdate my $date = format_gmdate; "format_gmdate" is identical to "format_date", but it will return a string indicating the time in Greenwich Mean Time, rather than local time. "format_gmdate" is exported on demand, but not by default. PERL EMAIL PROJECT
This module is maintained by the Perl Email Project <http://emailproject.perl.org/wiki/Email::Date> SEE ALSO
Email::Abstract, Time::Piece, Date::Parse, perl. AUTHOR
Casey West, <casey@geeknest.com>. Ricardo SIGNES, <rjbs@cpan.org>. COPYRIGHT
Copyright (c) 2004 Casey West. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2007-12-01 Email::Date(3pm)
All times are GMT -4. The time now is 03:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy