Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

timed email reminder

by data67 (Monk)
on Oct 11, 2001 at 19:57 UTC ( [id://118245]=perlquestion: print w/replies, xml ) Need Help??

data67 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to come up with a program that will send a reminder to specified email addreses every 6th day till the end of the month (e.g., if month is 31 days send e-mail on th 25th). The tricky part is that i want be able to do this with either  POSIX qw(strftime) or localtime(). As always, Thanks in advance
p.s., I am aware that Date::Calc will make this easy but that is not an option for some reason :-)

Replies are listed 'Best First'.
On Artificial Unspecified Constraints
by merlyn (Sage) on Oct 11, 2001 at 20:05 UTC
    p.s., I am aware that Date::Calc will make this easy but that is not an option for some reason :-)
    Is the reason one of:
    • This is homework
    • You don't know because you're not the one solving this problem, and that was given as an artificial constraint
    • It has to be fast
    • You don't know how to install modules into your own space
    • Even though you're root, you don't know how to install modules, period
    • Something else I didn't think of in 30 seconds
    I really get a bit annoyed when someone says "I want to do $x, but it can't include obvious solution $y", because that doesn't tell me anything about how close to $y I can get.

    Please explain further.

    -- Randal L. Schwartz, Perl hacker

      The reason that i can't use Date::Calc now is that i am running Perl 4.0 and i can't upgrade now. If this does not work, you guessed it...
        i am running Perl 4.0 and i can't upgrade now.
        Uh, exactly the same question occurs to me. Why? Why have you introduced this constraint, because removing it would solve most (if not all) of your problems?

        -- Randal L. Schwartz, Perl hacker

        Are you writing new code or trying add an enhancement/fix to 1000's of lines of legacy code in a short amount of time?
        If you have legacy code, keep separate installations of perl so that anything new can be done in the latest/greatest ways with the latest/greatest modules, and you can convert legacy code at your leisure until you can just get rid of Perl 4.
Re: timed email reminder
by thatguy (Parson) on Oct 11, 2001 at 20:08 UTC
    warning not perl, cron:
    in crontab:  0 0 0-31/6 * * echo "reminder" | mail soinso@example.com

    in perl, Date::Calc really is your best bet.

    Take a look around cpan for some other date modules and look at localtime..
    -p

      Ha! As it happens I'm actually working on cron in Perl for PPT. I was planning on posting it to perlmonks when done to ask for comments and optimizations... A functional but not yet fully complete version is here:

      http://web.mit.edu/belg4mit/Public/cron UPDATE: it now lives at: http://pthbb.org/software/crond/

      Of particular interest are the non-standard options -f and -X

      -f allows you to specify a crontab in a non-standard location

      Stuff to do: security (setuid and setgid) checking crontab update times and reloading as necessary

      internal mailer (would be perfect for this, just set the crontab entry to cat a file...) some other odds and ends

Re: timed email reminder
by buckaduck (Chaplain) on Oct 11, 2001 at 21:23 UTC
    I think some of the previous answers may have misunderstood the question. My interpretation is that you want to perform an action 6 days before the end of each month. (NOT every sixth day). My apologies if I'm wrong.

    If I'm right, you could use localtime to check the date six days from now, and see if it will be the 1st of the month:

    my $six_days_from_now = (localtime(time + 6*24*60*60))[3]; if ($six_days_from_now == 1) { Do_Action(); }

    buckaduck

Re: timed email reminder
by broquaint (Abbot) on Oct 11, 2001 at 20:12 UTC
    Well I'm going to go under the assumption that you don't have access to things like cron (or at for that matter), as they are usually the tools of choice. Also I'm not sure why you'd want to restrict yourself to 2 date functions that are used primarily for formatting, anyhoo -
    use strict; my $day = (localtime())[3]; while($day < 31) { if(0 == $day % 6) { do_email_program_thingy(); } else { sleep(60 * 60 * 24); } $day = (localtime())[3]; }
    This should do something every 6th day, otherwise it just sleeps. This isn't particularly elegant code, or robust for that matter, so I wouldn't recommend a copy'n'paste ;o)
    HTH

    broquaint

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://118245]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-18 20:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found