How to get timestamp of file into ksh script

Hi -
I need to run a script via cron which will do some ldapsearches. One of the search parameters will be modifytimestamp.

I need to have some way of storing the timestamp of the last time the script ran, and then retrieving that timestamp to use in the ldapsearch command (i.e. modifytimestamp >= retrieved_ts) for when the script next runs.

Any suggestions please? I guess I could "touch" a file as a marker before and after executing the ldapsearch but I am not sure how to get the timestamp of the file into the ldapsearch query.
Cheers

how does your query look like. Is it in some predefined format like hh:mm

you can always get the timestamp from ls -l filename| awk '{sub(/:/,"",$8);print $8}'

store this into a variable and then compare it with the time from the date command
echo `date +"%k%M"`

cheers,
Devaraj Takhellambam

Or with the stat command:

retrieved_ts=$(stat -c %y file | cut -d' ' -f1)

Thanks for the replies.

Unfortunately I don't have the stat command available in my AIX envt.

The timestamp needs to be in this format : 20090425000000
so yyyymmddhhmmss

Maybe it would be easier to just write/append the timestamp to a file and read the last entry from that? I just feel there has to be a neater way of doing this!

How do I get the timestamp in the format I want from something like :
ls -l $FILE | awk '{sub(/:/,"",$8);print $8}' ?

If the seconds don't matter you can do something like:

ls -l file | awk '{s=$6$7;gsub("-| |:","",s);print s}' 

If you want two zero's after the time you can add "00" after the s in the print statement.

what you can possibly do is ..in you ldap script, before it completes successfully, touch the logfile so tht the file will have the latest timestamp (you can write sme msg to the logfile)

then use

lastrun=`ls -l --time-style='full-iso' add | awk '{s=$6$7;gsub(/[:-]/,"",s);print substr(s,1,14)}' `
now=$(echo `date +"%Y%m%d%H%M%S"`)

then compare the above two variable

if [[ $now < $lastrun ]]; then
echo "Greater"
else
echo "Lower"
fi

cheers,
Devaraj Takhellambam