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 > Time Calculations in Shell
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Time Calculations in Shell

Réponse
 
LinkBack Outils de la discussion
Vieux 16/03/2008, 01h07   #1
Erwin Lindemann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Time Calculations in Shell


Suppose there is a file, f.

Is it possible to calculate every date (in YYYY-MM-DD format) that

a) falls between the last modification date of f and the current time, and
b) is a certain day of the week, say Wednesday or Saturday

in sh?

The idea is, I want to call a program with YYYY-MM-DD as parameter with
YYYY-MM-DD being every Saturday and Wednesday since the last time the
script was run.

In C, I'd probably start with the start date in seconds since the epoch,
check what day of week it is and add number of seconds till desired day of
week and then number of seconds in a week until we're in the future.

Can something like that be done in a shell script?

(preferably POSIX, but GNU should also be available on the target machine)

Thanks

--
Erwin Lindemann

  Réponse avec citation
Vieux 16/03/2008, 01h28   #2
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Time Calculations in Shell

On 2008-03-16, Erwin Lindemann wrote:
>
> Suppose there is a file, f.
>
> Is it possible to calculate every date (in YYYY-MM-DD format) that
>
> a) falls between the last modification date of f and the current time, and
> b) is a certain day of the week, say Wednesday or Saturday
>
> in sh?
>
> The idea is, I want to call a program with YYYY-MM-DD as parameter with
> YYYY-MM-DD being every Saturday and Wednesday since the last time the
> script was run.
>
> In C, I'd probably start with the start date in seconds since the epoch,


With GNU date, that is available using the %s specifier.

> check what day of week it is and add number of seconds till desired day of
> week and then number of seconds in a week until we're in the future.
>
> Can something like that be done in a shell script?
>
> (preferably POSIX, but GNU should also be available on the target machine)


Try the date arithmetic section of the FAQ:
<http://cfaj.freeshell.org/shell/cus-faq.html#6>

Also, Chapter 8 of my book, which is online at
<http://cfaj.freeshell.org/shell/ssr/08-The-Dating-Game.shtml>

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 16/03/2008, 05h07   #3
William James
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Time Calculations in Shell

On Mar 15, 6:07 pm, Erwin Lindemann <elind...@wupp.invalid> wrote:
> Suppose there is a file, f.
>
> Is it possible to calculate every date (in YYYY-MM-DD format) that
>
> a) falls between the last modification date of f and the current time, and
> b) is a certain day of the week, say Wednesday or Saturday
>
> in sh?
>
> The idea is, I want to call a program with YYYY-MM-DD as parameter with
> YYYY-MM-DD being every Saturday and Wednesday since the last time the
> script was run.
>
> In C, I'd probably start with the start date in seconds since the epoch,
> check what day of week it is and add number of seconds till desired day of
> week and then number of seconds in a week until we're in the future.
>
> Can something like that be done in a shell script?
>
> (preferably POSIX, but GNU should also be available on the target machine)
>
> Thanks
>
> --
> Erwin Lindemann


ruby -rdate -e'p Date:AYNAMES[Date.parse($*[0]).wday]==
"Saturday"' 2008-03-15
  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 17h51.


É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,11505 seconds with 11 queries