|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 -d $(date +'%Y-%m-%d') +'%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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Sep 11, 3:52 pm, Cyrus Kriticos <cyrus.kriti...@googlemail.com>
wrote: > littleh...@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 -d $(date +'%Y-%m-%d') +'%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 Quick question- are you using Solaris? I don;t have the '-d' flag for the format. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Sep 11, 2:12 pm, littleh...@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 > 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. #!ruby require 'date' Dir['foobar*'].each{|f| f =~ /(\d\d)(\d\d)(\d\d)$/ date = Date.parse( "20"+[$3,$1,$2].join("-") ) puts f if (Date.today - date) > 30 } |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
littlehere@gmail.com wrote:
> Cyrus Kriticos wrote: >> [bash] >> >> $ FILENAME="foobar1_090207" >> $ TIME="${FILENAME#*_}" >> >> $ PAST="$(date -d "20${TIME:4:2}-${TIME:0:2}-${TIME:2:2}" +'%s')" >> $ NOW=$(date -d $(date +'%Y-%m-%d') +'%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 > > Quick question- are you using Solaris? I don;t have the '-d' flag for > the format. Linux, sorry. -- Best regards | "The only way to really learn scripting is to write Cyrus | scripts." -- Advanced Bash-Scripting Guide |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Cyrus Kriticos wrote:
> 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 -d $(date +'%Y-%m-%d') +'%s') $ NOW=$(date -d $(date +'%Y-%m-%d') +'%s') ; echo $NOW 1189552546 $ NOW=$(date +'%s') ; echo $NOW 1189552546 You're thinking too complex, I suppose. :-) (Or any trick I am missing?) Janis > > $ let DIFF=(NOW-PAST)/60/60/24 > $ echo "diff in days: $DIFF" > diff in days: 9 > |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
Janis Papanagnou wrote: > Cyrus Kriticos wrote: >> >> $ NOW=$(date -d $(date +'%Y-%m-%d') +'%s') > > $ NOW=$(date -d $(date +'%Y-%m-%d') +'%s') ; echo $NOW > 1189552546 > > $ NOW=$(date +'%s') ; echo $NOW > 1189552546 > > You're thinking too complex, I suppose. :-) > (Or any trick I am missing?) # seconds since 1970-01-01 to midnight $ NOW=$(date -d $(date +'%Y-%m-%d') +'%s') ; echo $NOW 1189548000 # seconds since 1970-01-01 to now $ NOW=$(date +'%s') ; echo $NOW 1189569887 $ date --version | head -n 1 date (GNU coreutils) 5.97 -- Best regards | "The only way to really learn scripting is to write Cyrus | scripts." -- Advanced Bash-Scripting Guide |
|
![]() |
| Outils de la discussion | |
|
|