PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Script to compare dates and notify
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Script to compare dates and notify

Réponse
 
LinkBack Outils de la discussion
Vieux 11/09/2007, 20h12   #1
littlehelphere@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Script to compare dates and notify

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.

  Réponse avec citation
Vieux 11/09/2007, 20h37   #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
Vieux 11/09/2007, 20h52   #3
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 -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
  Réponse avec citation
Vieux 11/09/2007, 20h59   #4
littlehelphere@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Script to compare dates and notify

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.

  Réponse avec citation
Vieux 11/09/2007, 21h15   #5
William James
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Script to compare dates and notify

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
}

  Réponse avec citation
Vieux 11/09/2007, 21h32   #6
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Script to compare dates and notify

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
  Réponse avec citation
Vieux 12/09/2007, 00h19   #7
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Script to compare dates and notify

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
>

  Réponse avec citation
Vieux 12/09/2007, 05h08   #8
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Script to compare dates and notify


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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h23.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18455 seconds with 16 queries