I'm trying to create a shell script (#!/bin/sh) which should tell me the age of a file in minutes...
I have a process, which delivers me all 15 minutes a new file and I want to have a monitoring script, which sends me an email, if the present file is older than 20 minutes.
This uses the stat command, which I am not sure is available in your shell. It works by converting everything to epoch time, and in this case is checking for files within 3600 seconds (60 minutes). But, perhaps playing with these commands might get you started.
Will you be running your monitoring script from "cron"? If so, how frequently and during what hours and on what days of the week?
It is easy to write a script to run from cron which maintains a reference file with a timestamp 20 mins old but remember that if run once a minute such a cron would run 1440 times a day. If you really don't need to be that accurate, could you check every 10 mins or more?
AlphaLexman is correct. The "last modified" timestamp is the most useful and is the one used by "ls -la" and "find -mtime" etc..
The "-ctime" timestamp is the timestamp when the inode was last changed. Some backup software changes this timestamp to mark the file "backed up".
Earlier I was trying to avoid the epoch date arithmetic or writing a "C" or "perl" (or whatever) program.
There are many techniques to find files which are less than 20 minutes old even if you don't have the GNU version of "find" - which offers this sort of search as standard.
Let's find out what you are trying to do in more detail.
I don't use the crontab for this monitoring file... it's called from a scheduler of the application installed on this server. I run it monday to friday between 07:00 and 19:00.
I want to run the script every 5 minutes ...
I can use every date available ... the file is written once and will be overwritten when a new file arrives. There is never a change on the file.
The only thing I need is to check if the file is older than 20 minutes.
If there is a better or easier way than use the epoch time, it's OK for me...
I don't care which technic is used, I just need a solution