Test file age
From Noah.org
Revision as of 19:23, 6 December 2007 by Root (talk | contribs) (New page: Category:Engineering This shows how to check if a file is older than a given date using Bash. I use this to test the age of my server backup log. If the log is more than a day old then...)
This shows how to check if a file is older than a given date using Bash. I use this to test the age of my server backup log. If the log is more than a day old then I send an alert.
MAXAGE=`expr 60 \* 60 \* 24` # seconds in a day # file age in seconds = current_time - file_modification_time. FILEAGE=$(($(date +%s) - $(stat -c '%Y' "$FILE"))) test $FILEAGE -lt $MAXAGE && { echo "$FILE is less than $MAXAGE seconds old." }