Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run script depending on file date/time 1

Status
Not open for further replies.

emikoo

Technical User
Jul 12, 2002
37
NL
Hi,

We run a script using crontab and would like the following statement to be included:

In case the date and time stamp of a certain file compared to the current date and time is more then 2 hours, I want to run the script, else quit.

Thnxs,

EK
 
hi hard to do in sh-script!!
use stat() in 'perl' or 'c'
and check st_[acm]time.

for more: man stat ------------ jamisar
Einfachheit ist das Resultat der Reife. (Friedrich Schiller)
Simplicity is the fruit of maturity.
 
Or try this - untested
#/bin/ksh
fhh=`ls -lrt yourfilename|cut -c49-50`
fmm=`ls -lrt yourfilename|cut -c52-53`
hhmm=`date +%H +%M`
fhm=`echo ${fhh}${fmm}`
fhm=`expr "$fhm" + 200`
if [ ${hhmm} -gt ${fhm} ]
then
Do whatever you need to......
fi

You could refine this to check the correct day and month too
and if the file could be over a year old then the year appears in the 49th/50th cols
HTH ;-)
Dickie Bird
db@dickiebird.freeserve.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top