Operating System - HP-UX
1753534 Members
5735 Online
108795 Solutions
New Discussion юеВ

Using mtime in the find command...

 
SOLVED
Go to solution
Carlo Henrico_1
Regular Advisor

Using mtime in the find command...

Using mtime in the find command is in multiples of 24 hours. However, I need to find files created more than minutes ago, and ignore those created in the last 20 minutes.

Any ideas how I can do this please?

Thanks

Carlo
Live fast, die young - enjoy a good looking corpse!
6 REPLIES 6
Paula J Frazer-Campbell
Honored Contributor

Re: Using mtime in the find command...

Hi Carlo


Try Here:-


http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x046b42308663d611abdb0090277a778c,00.html


Paula
If you can spell SysAdmin then you is one - anon
john korterman
Honored Contributor

Re: Using mtime in the find command...

Hi,
first create a file to use as a reference point on the time line for 20 minutes ago. If 20 minutes ago was May 28, 2003 11:19 you could create the file like this:
# touch 0528111903 /tmp/whenever

Check that the mtime for this file is correct:
# ls -l /tmp/whenever
-rw-r--r-- 1 jxk users 0 Maj 28 11:19 /tmp/whenever

Then cd to the directory where you want to search and
# find . ! -newer /tmp/whenever

which will list files last modified before /tmp/whenever.

regards,
John K.
it would be nice if you always got a second chance
Carlo Henrico_1
Regular Advisor

Re: Using mtime in the find command...

That's great so far but I need to script this and to do this:

touch 0528111903 /tmp/whenever

I will need to build this "0528111903" string in a script minus 20 minutes...

Now date +%m%d%H%M%S gives me the current time but how do I make it "20 minutes ago"?

Thanks

Carlo
Live fast, die young - enjoy a good looking corpse!
Ken Penland_1
Trusted Contributor

Re: Using mtime in the find command...

does this script run every 20 minutes? Cause if it does, you could have it touch a file in /tmp or whatever...so that the next time it runs, that file will be 20 minutes old, they you could always just use the newer command using that file.
'
john korterman
Honored Contributor
Solution

Re: Using mtime in the find command...

Hi again,
if you have no other possibility, you can try this where SECONDS_SINCE should hold the path to the attached script:

#!/usr/bin/sh

# Construct REF_FILE, always 20 minutes old
#
REF_FILE=/tmp/whenever
SECONDS_SINCE=$(return_seconds.sh) # path to attached....

# Subtract 20 minutes = 1200 seconds, thus:
TWENTY_AGO=$(( ${SECONDS_SINCE} - 1200 ))

# Set timezone...
export TZ=METMETDST

# Convert 20 minutes ago to a human date
HUMAN_DATE=$( echo "0d${TWENTY_AGO}=Y" | adb )

# Extract necessary info..
YEAR_20_AGO=$( echo ${HUMAN_DATE} | awk '{print $1}')
MONTH_20_AGO=$( echo ${HUMAN_DATE} | awk '{print $2}')
DAY_20_AGO=$( echo ${HUMAN_DATE} | awk '{print $3}')
HOUR_20_AGO=$( echo ${HUMAN_DATE} | awk '{print $4}'| awk -F: '{print $1}')
MINUTE_20_AGO=$( echo ${HUMAN_DATE} | awk '{print $4}'| awk -F: '{print $2}')
SEC_20_AGO=$( echo ${HUMAN_DATE} | awk '{print $4}'| awk -F: '{print $3}')
# Convert Month name to number
case $MONTH_20_AGO in
Jan) MONTH_NO=01;;
Feb) MONTH_NO=02;;
Mar) MONTH_NO=03;;
Apr) MONTH_NO=04;;
May|Maj) MONTH_NO=05;;
Jun) MONTH_NO=06;;
Jul) MONTH_NO=07;;
Aug) MONTH_NO=08;;
Sep) MONTH_NO=09;;
Oct) MONTH_NO=10;;
Nov) MONTH_NO=1i1;;
Dec) MONTH_NO=1i2;;
esac

# Delete existing - and create new reference file...
if [ -w $REF_FILE} ]
then
rm $REF_FILE
fi
touch ${YEAR_20_AGO}${MONTH_NO}${DAY_20_AGO}${HOUR_20_AGO}${MINUTE_20_AGO} $REF_
FILE
# Check that file is ok..
echo $REF_FILE|cpio -o 2>/dev/null|cpio -ivt 2>/dev/null

# End of example,Now use REF_FILE...

As the above was cut and pasted I do not know how it will appear - it worked on my system. You should adapt the month conversion in the case structure to what is appropiate for yout $LANG. May the TZ must also be changed, and perhaps you should then wait for the inevitable perl one-liner..

regards,
John K



it would be nice if you always got a second chance
john korterman
Honored Contributor

Re: Using mtime in the find command...

sorry, a few corrections:

Nov) MONTH_NO=1i1;;
Dec) MONTH_NO=1i2;;

1i1 should of course be 11
and 1i2 should be 12

$REF_
FILE
should be $REF_FILE

regards,
John K.
it would be nice if you always got a second chance