Afficher un message
Vieux 11/09/2007, 21h37   #2
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Script to compare dates and notify

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
  Réponse avec citation
 
Page generated in 0,05422 seconds with 9 queries