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

I need to create a program for sending Bulk News letter.I m planned to create a program which will send some mails(Suppose 20 mails) in between the interval of 30 seconds.I have written a PHP Program For that.My purpose is to create a crontab entry when administrator clicks the send Button.. For more clearly, When Administator Clicks on the "start sending button"(PHP SIDE) it should call a Perl File ,That PERL file create a Crontab Entry and adds into the crontab file at that instant only.When All the mails are send There is a status showing that No mails to send right now..At that Time administartor presses the "Stop" button, then it removes the crontab entry from the file.But i dont how to add a crontab entry in to the crontab file at a particular instant.I am requesting you to give me the slution as soon as early please. I am a New Bee in PERL..
  • Comment on How do I insert a crontab entry into crontab file using PERL

Replies are listed 'Best First'.
Re: How do I insert a crontab entry into crontab file using PERL
by CountZero (Bishop) on Oct 01, 2005 at 12:46 UTC
    What would be wrong with making a CGI-page with a "Send Now!" button which directly starts sending the mail? Is there any good reason why you have to go the PHP->Perl->crontab->sendmail way?

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: How do I insert a crontab entry into crontab file using PERL
by Ultra (Hermit) on Oct 01, 2005 at 12:12 UTC

    Cron's purpose is to run tasks periodically.

    You need at for running a job one time.

    Dodge This!
Re: How do I insert a crontab entry into crontab file using PERL
by graff (Chancellor) on Oct 01, 2005 at 15:28 UTC
    As Ultra pointed out, cron is really the wrong tool for this sort of task -- put all thoughts of cron out of your mind. And as CountZero pointed out, you don't seem to have any reason to make this so complicated.

    If you have message content in a text file, and a list of email addresses in another file, simply launch some kind of script (perl or shell) that will mail the text to the address list. (Or maybe there's some function or facility in PHP that handles this?)

    If you think it really can't be as simple as that, we can't give you any better answer yet, because you haven't told us what the complicating factors are.

Re: How do I insert a crontab entry into crontab file using PERL
by Anonymous Monk on Oct 02, 2005 at 00:40 UTC
    system ( "crontab -l > oldcrontab ; cp oldcrontab newcrontab ; echo ' +*/2 * * * * mystupidPERLscript.pl' >> newcrontab ; crontab newcrontab +" );
Re: How do I insert a crontab entry into crontab file using PERL
by TedPride (Priest) on Oct 02, 2005 at 23:12 UTC
    The problem with using a button on a web page is that the script will only continue sending as long as the browser is sitting there waiting for response. If you quit the browser in the middle, the process stops. I usually get around this by running my mailings while I sleep, but if you need your mailings done on a precise schedule, you need something like what Ultra suggested.
      The problem with using a button on a web page is that the script will only continue sending as long as the browser is sitting there waiting for response.

      Is that true? I really doubt that. Once you fire off a CGI-script, it will run its course, whether or not there is still a browser "listening". I don't think the webserver will kill off a script as soon as the browser closes.

      And in case the script starts an external program (as in the OP), that is certainly not getting killed off by the webserver.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law