Find command output gives one day before time stamp


 
Thread Tools Search this Thread
Operating Systems Solaris Find command output gives one day before time stamp
# 1  
Old 10-05-2012
Find command output gives one day before time stamp

Hi All,

I am listing the files which are 4 hours older. For this first I have creted a dummy file with the 4 hours before timestamp, then I am using the below find command,
Code:
find /path/ -type f ! -newer 4_hours_oledr_file -exec ls -lrt {} \;

I am getting the files which are older than the four hours only. But in the op the time stamp of the files coming as one day older.

Code:
/path/ack_test_20121004155730774.X12,Oct 4 15:57
/path/ack_test_20121004160351369.X12,Oct 4 16:03
/path/ack_test__20121004160621672.X12,Oct 4 16:06

actually these three files are created oct 5th only. but in the op it is showing as oct 4th.

Could yopu please help me to resolve this issue?

Thanks in advance!

Last edited by radoulov; 10-05-2012 at 06:17 AM..
# 2  
Old 10-05-2012
I can confirm that this should work. There is obviously something not quite right.

Firstly, how are you creating your timestamp file??

The file might contain the output of the date command but that would be irrelevant. It is the inode date/time that find will use.

If you:

Code:
 
ls -l <timestamp file>

what does it say?

You can modify the inode contents (date/time) of a file to set it to whatever you want.

So, how are you "creating" your timestamp file?


Also, just noticed that you have a bang (!) before the -newer which will invert the function!!! This will give you NOT NEWER. Remove the bang.

I hope that helps. Having read your post again I'm not sure I understand your question.

Last edited by hicksd8; 10-05-2012 at 05:54 AM..
# 3  
Old 10-05-2012
Quote:
Originally Posted by hicksd8
I can confirm that this should work. There is obviously something not quite right.

Firstly, how are you creating your timestamp file??

The file might contain the output of the date command but that would be irrelevant. It is the inode date/time that find will use.

If you:

Code:
 
ls -l <timestamp file>

what does it say?

You can modify the inode contents (date/time) of a file to set it to whatever you want.

So, how are you "creating" your timestamp file?


Also, just noticed that you have a bang (!) before the -newer which will invert the function!!! This will give you NOT NEWER. Remove the bang.

I hope that helps. Having read your post again I'm not sure I understand your question.
Thanks for your response!
Code:
Y_DAY=`/usr/bin/perl -le 'print scalar localtime (time() - 240*60);'|nawk '{printf "%3s %3s %02d %s %04d",$1,$2,$3,$4,$5}'`
Y_YR=`echo $Y_DAY | awk '{print $5}'`
Y_MON=`echo $Y_DAY | awk '{print $2}'`
Y_DT=`echo $Y_DAY | awk '{print $3}'`
Y_HR=`echo $Y_DAY | awk '{print $4}' | cut -d":" -f1 `
Y_MIN=`echo $Y_DAY | awk '{print $4}' | cut -d":" -f2 `
 
 
# Convert Month name to month number
 
case $Y_MON in
"Jan") NEW_Mon=01
;;
"Feb") NEW_Mon=02
;;
"Mar") NEW_Mon=03
;;
"Apr") NEW_Mon=04
;;
"May") NEW_Mon=05
;;
"Jun") NEW_Mon=06
;;
"Jul") NEW_Mon=07
;;
"Aug") NEW_Mon=08
;;
"Sep") NEW_Mon=09
;;
"Oct") NEW_Mon=10
;;
"Nov") NEW_Mon=11
;;
"Dec") NEW_Mon=12
;;
*) echo "Invalid output"
;;
esac
 
REF_DT_STAMP=`echo $Y_YR$NEW_Mon$Y_DT$Y_HR$Y_MIN `
 
# create a file in the script dir for the reference
FILE_NEW=/path/4hours-Old-Temp-RefFile.txt
touch -t $REF_DT_STAMP $FILE_NEW

I am using the above to create the 4 hours older timestamp file.

I want to list the files which should not be the newer, so tat y i am using the ! (bang).

Thanks!

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.
# 4  
Old 10-05-2012
So if you run the script to create your timestamp file and then immediately:

Code:
 
ls -l <timestamp file>

is the inode date/time four hours ago? Just to check that the script is doing what we think it is.

Also, please try this without the space between the bang and -newer.
# 5  
Old 10-05-2012
Quote:
Originally Posted by hicksd8
So if you run the script to create your timestamp file and then immediately:

Code:
 
ls -l <timestamp file>

is the inode date/time four hours ago? Just to check that the script is doing what we think it is.

Also, please try this without the space between the bang and -newer.

Getting the output,

-rw-rw-r-- 1 b2binta1 b2badmin 0 Oct 4 22:31 /path/4hours-Old-Temp-RefFile.txt
# 6  
Old 10-05-2012
I don't know what timezone you're in. Is this date/time correct (for four hours ago)? October 4, 22:31

If it is then your code seems to be working correctly for creating the timestamp file.
# 7  
Old 10-05-2012
Quote:
Originally Posted by velava
Getting the output,

-rw-rw-r-- 1 b2binta1 b2badmin 0 Oct 4 22:31 /path/4hours-Old-Temp-RefFile.txt

But when i checking the /path/ the reference timestamp file it is showing as exactly 4 hours from now oct 5th 11:01.

how it is?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Diplay current time stamp in the output

I want to display the command output in a particular format. can you please suggest how can i do this Output of the command Name= XYZ Company= Alpha Department= Accounts Country= Singapore Name=MNC Company= Beta Department= Engineering country=Malta Name=ABC Company=Gamma... (2 Replies)
Discussion started by: swets
2 Replies

2. Shell Programming and Scripting

How do i find a file with the current time stamp in it??

I want to find a file using find or any utility having the current date time stamp..... I have an alternate way to do that.... but that is too way out of logic... so looking out something with find itself (5 Replies)
Discussion started by: nikhil jain
5 Replies

3. Shell Programming and Scripting

How to change time stamp with touch command?

Hi, I wish to change time stamp of a directory with all its subdirectories and files on server. I am able to find following two ways but want to know which will be the better one. I have not tried anyone of them because I am not sure if it can effect my data: find * -type d -exec touch... (5 Replies)
Discussion started by: bioinfo
5 Replies

4. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

5. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

6. Shell Programming and Scripting

regarding time stamp

hi everyone i am facing a strange problem here suppose content of my file is a=1,2,3 b=2,3,4 c=4,5,6 time= now the problem is i want to add value in front of time variable and the value should be i format only "HHMMSS" so it should be like this a=1,2,3 b=2,3,4 c=4,5,6... (3 Replies)
Discussion started by: aishsimplesweet
3 Replies

7. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

8. Shell Programming and Scripting

greping with time stamp

Hi all, I want to grep a file name with time stamp as 30 minutes how can i??. Ex I will getting outputs in a file every minutes I want to grep it by a time intervals of 30 and show it . Any help will be great ! Thanks, Arun. (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

9. UNIX for Advanced & Expert Users

output of the time command ?

can someone tell me the meaning of this commnad, If you want to see a grand total of CPU time for a program when it finishes running, you can use the time command. At the Unix prompt, enter: time java myprog Replace myprog with the name of the program you are running. The following is an... (2 Replies)
Discussion started by: ldpathak
2 Replies

10. Shell Programming and Scripting

Write a shell script to find whether the first day of the month is a working day

Hi , I am relatively new to unix... Can u pls help me out to find out if the first day of the month is a working day ie from (Monday to Friday)...using Date and If clause in Korn shell.. This is very urgent. Thanks for ur help... (7 Replies)
Discussion started by: phani
7 Replies
Login or Register to Ask a Question