littlehere@gmail.com wrote:
> I am trying to put together a script to compare the dates of a file
> and send out an email notification if the date on the file is beyond
> 30 calendar days. However, I am having a bit of trouble. The file
> format is <filename>_%m%d%y. So for example
> foobar1_090207
> foorbar2_090307
> foorbar3_091507
^^
future? typo?
> I parse the file so I am just left with the date extension from
> there I want to be notified of any file over the 30 day mark.
>
> I tried using expr and setting up a variable for the 30 days but its
> not working. Any would be appreciated. Thanks.
[bash]
$ FILENAME="foobar1_090207"
$ TIME="${FILENAME#*_}"
$ PAST="$(date -d "20${TIME:4:2}-${TIME:0:2}-${TIME:2:2}" +'%s')"
$ NOW="$(date +'%s')"
$ let DIFF=(NOW-PAST)/60/60/24
$ echo "diff in days: $DIFF"
diff in days: 9
--
Best regards | "The only way to really learn scripting is to write
Cyrus | scripts." -- Advanced Bash-Scripting Guide