Comparing the timestamp of the file to current time


 
Thread Tools Search this Thread
Operating Systems HP-UX Comparing the timestamp of the file to current time
# 1  
Old 03-20-2015
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 want to use mmin ,im on hp unix which doesnt support mmin option .Thank you
# 2  
Old 03-20-2015
Hello Haadiya,

Following may help you in same.
Code:
VAL=`find -type f -mmin +120 -iname "Input_file"`
if [[ -n $VAL ]]
then
       echo "File is OLDER than 2 hours."
else
       echo "File is NOT older than 2 hours."
fi

I have just provided and example for same in if else statements you can provide actions too which you want to perform, hope this helps.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 03-20-2015
Hello Ravi,

Im on hp unix which doesn't support mmin option ,and my filename is dynamic i dont know the file name.what im trying to do is

1) Run the script every 2 hours and check if the last file generated was more than 2 hours old.
below are my tries

Last file = ` ls -ltr | awk '{print $9}' | tail -1`
Time of Last file = ` ls -ltr | awk '{print $6,$7,$8}'|tail -1`


Compare with current time to see if its older than 2 hours or not

2) If there is a latest file generated which is not older than 2 hours, check if the latest file is empty.
empty means -
If 'cat filename | wc -l" = 0 (zero lines in the file)

if empty do something

Im working on building this
# 4  
Old 03-20-2015
Hello Haadiya,

Could you please try following and let me know if this helps.
Code:
NAME_FILE=`ls -lhtr | awk '($1 !~ /^d/) {print $9}' | tail -1`
CHECK_FILE=`find -maxdepth 1 -type f -name $NAME_FILE -mmin +120`
if [[ -z $CHECK_FILE ]]
then
 if [[ -s $NAME_FILE ]]
 then
  echo "File is NOT empty."
 else
  echo "Do operations as you wish."
 fi
else
 echo "File is OLDER than 2 hours."
fi

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 03-20-2015
Do you have a touch command that allows you to create a file 2 hours old? Then use this for the -newer find primary.
This User Gave Thanks to RudiC For This Post:
# 6  
Old 03-20-2015
Hello RudiC,

Yeah you are right,im saw few threads using touch and -newer option,the thing is, im not suppose to create any file in that dir,thats the reason i didnt go for that.

Hello Ravi,
Just an example of mmin in my unix box.I have hp ux 11.3
$ find . -mmin -60 -size 0
find: bad option -mmin
your solution would throw an error ,anyways i ll keep trying

I used something like this earlier

dir="/home/user"
found=`find "$dir" -type f \( -mtime +7200 -o -size 0 \)`
if [ -n "$found" ]; then
echo "There are files older than 2 hours OR with size 0:
$found"
fi


then realized mmin doesnt work for me.Thanks iI llwork on finding some alternative

Last edited by haadiya; 03-20-2015 at 08:57 AM..
# 7  
Old 03-20-2015
You don't need to create that file in the target dir, create it in your home dir. Or in /tmp.
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

Based on the first & last timestamp of the file, need to calculate the time taken to complete

Below is the sample file: 287 DEBUG syndesis.pb.util.ITraceManager - syOID=ELntNetwork:1005Mon Oct 15 17:18:21 IST 2012 <ELClientManagerenEmsSession() > Setting Java Properties 287 DEBUG syndesis.pb.util.ITraceManager - syOID=ELntNetwork:1005Mon Oct 15 17:18:21 IST 2012... (1 Reply)
Discussion started by: ashok.kumar
1 Replies

4. Shell Programming and Scripting

Compare current time to timestamp on a file

I'm trying to compare 2 dates between current time and the timestamp on a file. The date format is mmdd Both return Apr 1 but when using if statement line 11: Apr 1: command not found error is returned #!/bin/sh log="DateLog" Current_Date=`date +%b%e` Filepmdate=`ls -l /file.txt |... (1 Reply)
Discussion started by: cillmor
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. 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

7. 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

8. Shell Programming and Scripting

Reading Hours and Minutes from file and comparing with current

Hi, Time till when the application should run is indicated in a file. First line is hour and second line is minute. file: 10 55 Means my application should run till 10:55. Now in a shell script, i am trying to make that logic but with no luck. min=`tail -n 1 /file_with_time`... (1 Reply)
Discussion started by: SGD
1 Replies

9. UNIX for Dummies Questions & Answers

comparing timestamp of a file with its touched version

Hi, I'm new to unix,I wanna know how can I compare timestamp of a file with its touched version.i.e I want to be sure if the touch command has worked properly i.e if the file has been touched then a msg should be printed saying success else failure.All this to be incurred in a script. Any... (2 Replies)
Discussion started by: prince258
2 Replies

10. Shell Programming and Scripting

How can I create a file with current time - 60 minutes

I'm using k-shell in unix and I want to create a file with the current system time - 60 minutes. I know I can use touch to create the file, but I'm having trouble specifying how tell it to use the current time less 60 minutes. Any ideas??? (4 Replies)
Discussion started by: DaveyTN
4 Replies
Login or Register to Ask a Question