comparing timestamp of a file with its touched version


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers comparing timestamp of a file with its touched version
# 1  
Old 09-28-2008
Bug 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 suggestions are welcome.

Thanks in advance
# 2  
Old 09-28-2008
If the stat(1) utility is available, then here is an example of one way of doing it
Code:
#!/bin/bash

FILE=./testfile        # replace with your file
stat1=$(stat --printf="%Z" $FILE)
touch $FILE
stat2=$(stat --printf="%Z" $FILE)
if [[ $stat1 = $stat2 ]]
then
   echo "touch failed"
else
   echo "touch succeeded"
fi

~
# 3  
Old 09-29-2008
Quote:
Originally Posted by prince258
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 suggestions are welcome.

Thanks in advance
if you wanna check for the sucess or failuer of some command
check for $? after that command
e.g
Code:
 
touch filename
if [ $? -eq 0 ];then
echo "done"
else
echo "not done"
fi

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. UNIX for Advanced & Expert Users

Last touched file by a specific program ?

i have a directory where all .csv files are available. i have 3 perl programs(ex: a.pl,b.pl,c.pl) which continuously runs every 1 minute to scan all files in that directory. now i have 2 questions 1) how can i write an app lock on that particular folder to make sure only one program will scan... (4 Replies)
Discussion started by: sbjv
4 Replies

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

4. Shell Programming and Scripting

Copy a file from directroy/ prior version to the directory/ new version

How to copy a file from directroy/ prior version to the directory/ new version automatically. (4 Replies)
Discussion started by: roy1912
4 Replies

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

6. Shell Programming and Scripting

Getting a relative timestamp from timestamp stored in a file

Hi, I've a file in the following format 1999-APR-8 17:31:06 1500 3 45 1999-APR-8 17:31:15 1500 3 45 1999-APR-8 17:31:25 1500 3 45 1999-APR-8 17:31:30 1500 3 45 1999-APR-8 17:31:55 1500 3 45 1999-APR-8 17:32:06 1500 3 ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

7. UNIX for Dummies Questions & Answers

Never touched UNIX before.. Where do I start?

I will be taking a UNIX course as a part of my college Data Com concentration curriculum. Just thought it would be a good idea to get a little head start, since this class will most likely be quite difficult for someone like me. I never did any programming and I never dealt with Unix or Linux short... (3 Replies)
Discussion started by: ibex333
3 Replies

8. What is on Your Mind?

Finally I touched 1000.Yahooooo!!!

This, my venerable audience, is my 1000th post here. Thanks for your support and help..:b: ---Vidyadhar:) (4 Replies)
Discussion started by: vidyadhar85
4 Replies

9. UNIX for Dummies Questions & Answers

Comparing Version Numbers

Hi There! Apologies if this has been asked previously but I couldn't find the answer I was hoping for. Basically, all I want to do is compare the OS X version against the version that I require in my script. So I'm retrieving the OS version using defaults read, but how can I compare this... (10 Replies)
Discussion started by: davewg
10 Replies

10. Shell Programming and Scripting

comparing timestamp of two files

Hi! I need to copy a whole bunch of file from a build directory to my working directory. Many of these files already exist in my working directory. I need to copy only those files that have been modified since I last copied.. How do I compare the timestamp of two files, so that I would copy... (2 Replies)
Discussion started by: jyotipg
2 Replies
Login or Register to Ask a Question