Mike Schilli's Friendly Neighborhood Perl Shop

Home
USArundbrief.com
Resume
CPAN Modules
Articles in English
Articles in German
Mike's Script Archive
English-Japanese Translation Trainer
Adventures with O'Reilly's Safari
10 Easy Steps to Become a California Driver
Unofficial perlmonks.com IRC Channel
My Collection of Outage Pages
Prisma (Computer Club Deutschland)
Mike's Monologues
Mike's Script Archive: DailyOnce.pm

DailyOnce.pm - Utility to run scripts exactly once a day


NAME

    DailyOnce.pm - Utility to run scripts exactly once a day


DOWNLOAD

DailyOnce.pm


SYNOPSIS

    if(DailyOnce->new()->done_for_today()) {
        exit 0;
    }


DESCRIPTION

DailyOnce helps running scripts only once a day, even if they're being called several times a day, e.g. via a cronjob.

METHODS

<new()>
Create a new DailyOnce object. Optional parameter: tmpfile, to specify the file where DailyOnce stores the date:
    my $do = DailyOnce->new(tmpfile => "/tmp/foobar");

The name of the file defaults to /tmp/programname.dat.

<done_for_today()>
Checks if the script has been called already today and returns 1 if so and 0 otherwise. It will create a file to memorize this check.

If done_for_today() will be called the next time within the same day, it will return 1. When it will be called the next time on a new day, it will return 0.


EXAMPLES

    use Getopt::Std;
    use DailyOnce;
    getopts('o', \my %opts);
    if($opts{o} and DailyOnce->new()->done_for_today()) {
        print "Done for today already\n";
        exit 0;
    }
    # Normal processing ...


LEGALESE

Copyright 2004 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.


AUTHOR

2004, Mike Schilli <m@perlmeister.com>


Latest update: 20-Oct-2013