Sponsored Content
Top Forums Shell Programming and Scripting Compare current time to timestamp on a file Post 302409456 by frans on Thursday 1st of April 2010 08:32:20 AM
Old 04-01-2010
look at 'man date' if your date supports the -r option (retrieve from file).
The syntax would be very simple:
Code:
log="DateLog"
DATEC="$(date +%b%e)"
DATEF="$(date -r /message.txt +%b%e)"
echo "Current date : $DATEC"
echo "File date    : $DATEF"
if [ "$DATEC" = "$DATEF" ]
then    echo "Dates are the same" > /$log
else     echo "Dates are Not the same" > /$log
fi
exit 0

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

to compare latest logfile with the current running time of the script

how can i compare the latest log file with the current time.. consider i am running a script "a.sh" at 09:00 ( function of the script a.sh is to update the database ) this script is going to create logfile if the script is sucess in case of failure it is not going to create logfile.. ... (0 Replies)
Discussion started by: mail2sant
0 Replies

2. Shell Programming and Scripting

How to compare the mtime of a file with the current time?

Hi, I wondered if we could do this with shell script? How to compare the mtime of a file with the current time and check whether its less than 24 hours. Thanks.:b: (2 Replies)
Discussion started by: Krsh
2 Replies

3. AIX

how to grep and compare timestamp in a file with the current date

I want to read a log file from a particular location.In the logfile , lines contains timestamp.I need to compare the timestamp in the logfile with the current date.If the timpestamp in the log file is less than 4 hours then i need to read the file from that location.Below is the file format.Please... (1 Reply)
Discussion started by: achu
1 Replies

4. AIX

how to grep and compare timestamp in a file with the current date

I want to read a log file from a particular location.In the log file each line starts with timestamp.I need to compare the timestamp in the logfile with the current date.If the timpestamp in the log file is less than 4 hours then i need to read the file from that location.Below is the file... (1 Reply)
Discussion started by: achu
1 Replies

5. Shell Programming and Scripting

Compare file timestamp with current date. Diff must be 1 hour.

Hello, I've created the script below to compare the content of two files with a delay of an hour. After an hour, the lines that exist in both files, will be printed and executed. The script now uses a counter to countdown 50 minutes. But what I would prefer is to check the file timestamp of... (3 Replies)
Discussion started by: taipan
3 Replies

6. UNIX for Dummies Questions & Answers

How to compare current time with the input to variant?

Hi all, I have a simple script follow: ------------- #!/bin/bash echo -n " Enter the date of today: " read dateoftoday ------------- Now I want to compare the variant $dateoftoday with date of the system (now) in order to prevent user inputs the past date to $dateoftoday. I want to make... (3 Replies)
Discussion started by: axn_boy
3 Replies

7. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

8. Shell Programming and Scripting

To check timestamp in logfile and display lines upto 3 hours before current timestamp

Hi Friends, I have the following logfile. Currently time in india is 07/31/2014 12:33:34 and i have the following content in logfile. I want to display only those entries which contain string 'Exception' within last 3 hours. In this case, it would be the last line only I can get the... (12 Replies)
Discussion started by: srkmish
12 Replies

9. HP-UX

Comparing the timestamp of the file to current time

I have a file like this -rwxr-xr-x 1 rewq other 168 Jan 13 07:05 check_files.sh I want to compare (check_files.sh time) with the current time to see if its is older than 2 hours or not if it is not older than 2 hrs then do something.can someone help me on this?.I dont... (7 Replies)
Discussion started by: haadiya
7 Replies

10. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies
tapset::timestamp(3stap)												  tapset::timestamp(3stap)

NAME
tapset::timestamp - systemtap timestamp tapset DESCRIPTION
Each timestamp function returns a value to indicate when a function is executed. These returned values can then be used to indicate when an event occurred, provide an ordering for events, or compute the amount of time elapsed between two time stamps. get_cycles Processor cycle count See function::get_cycles(3stap) for details. jiffies Kernel jiffies count See function::jiffies(3stap) for details. HZ Kernel HZ See function::HZ(3stap) for details. SEE ALSO
function::get_cycles(3stap), function::jiffies(3stap), function::HZ(3stap), stap(1), stapprobes(3stap) IBM
--- tapset::timestamp(3stap)
All times are GMT -4. The time now is 09:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy