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

Hi, I have a script that checks a database for new information every 15 min. If there is something new it e-mails me, if there is nothing the script dies. I'm using crontab to run the script every 15 min. My problem is when the script dies, cron sends an e-mail to root. How can I get this script to die normally without producing a die() error? I'm a newbee to perl and programming, so please tell me there is an easy and mindless solution. :)

Replies are listed 'Best First'.
Re: Getting Perl to Die Gracefully
by blakem (Monsignor) on Sep 13, 2001 at 00:32 UTC
    If you are just trying to terminate the program normally w/o sending an error message, you can either fall of the end of your code, or call exit() explicitly.

    -Blake

      Ah, That's what I was looking for. Thank you very much.
Re: Getting Perl to Die Gracefully
by derby (Abbot) on Sep 13, 2001 at 01:46 UTC
    AM,

    This is really not a perl problem but a cron issue. If you man crontab you may see:

    After cron runs commands according to the contents of your crontab file, it mails you the output from standard output and standard error for these commands, unless you redirect standard output or standard error.

    so you need to ensure you do not print any messages to either STDERR or STDOUT. A lot of devs will take a different tact than the one you have. You could set up your script to only print the msg and not e-mail you (and not do anything but exit if nothing new). Then let the cron subsytem mail you the results.

    -derby

Re: Getting Perl to Die Gracefully
by buckaduck (Chaplain) on Sep 13, 2001 at 01:43 UTC
    If you're running your program with cron, any output (including errors) will be mailed to you (I'm guessing that you're running the program from root's crontab, since root is getting the mail).

    You can redirect your standard output and/or standard error in the crontab entry. Here's an example in sh syntax:

    0,15,30,45 * * * * /your/command >/dev/null 2>&1

    buckaduck

Re: Getting Perl to Die Gracefully
by nehlwyn (Acolyte) on Sep 13, 2001 at 01:40 UTC

    Greetings fellow monk ,

    From a newbie to a newbie :

    May i add to the complete answer you've already had that when you have such a simple question , try first perldoc perlfunc . A lot of perl functions are self-explicit ( even if there are lots of ways to make their use more elaborate and complicated ) . I'm sure that if you had seen "exit" in the perlfunc page , you would have guessed that was what you were looking for ...

    At the beginning , it may take twice as much time to find a solution , but then you learn twice as fast ... I think it's a good deal ;-)

    the little one.