Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

cronjobs and perl

by damian (Beadle)
on Sep 18, 2000 at 12:57 UTC ( #32931=perlquestion: print w/replies, xml ) Need Help??

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

another dumb newbie question, is there a possibily that a perl script will not run when executed via cron? i mean when i run my script manualy it does execute but with cron it won't. any suggestions or alternatives to cronjobs?

Replies are listed 'Best First'.
Re: cronjobs and perl
by zejames (Hermit) on Sep 18, 2000 at 14:16 UTC
    Another possibility is that you use some files in you script, and that you use them like this:

    open FILE,"my_data" or die "Error\n";

    or
    system("exec.pl");

    But you must be careful: you don't know what is the current directory of cron when it executes your script. So you must precise the entire path for files you use.
    e.g
    open FILE,"/my/path/my_data" or die "Error\n";

    or
    system("/my/path/exec.pl");


    Hope this helps

    Zejames
RE: cronjobs and perl
by Jonathan (Curate) on Sep 18, 2000 at 16:49 UTC
    This is probably more to do with your Unix environment than any particular Perl problem. A couple of things to check
    1, Does your script require any environment variables? (remember your profile is not run by cron)
    2, Have you checked that your cron line is correct?
    3, Find out if cron doesn't like it and direct the standard error from cron output to a file i.e

    30 * * * * /path_to_script/script 2>/tmp/cron.wrong
      hi jonathan, u see my script's purpose is to update the webpage automatically. it goes like this:
      30 * * * * /usr/local/httpd/cgi-bin/admin/update.pl --exclusives
      is there a way i can send an e-mail to myself to check if the script successfully ran? i know i am not a good sysadmin forgive me. thanks
        In your crontab:
        MAIL=jonathan

        ... or whatever local account name you have on that box.
        Forgive me if I'm being more stupid than usual today and have misunderstood.
        Do you want your script to E-mail you?
        If so, (watch the purists flame me ;-) I often just use the Unix mail or mailx command within backticks - quick and dirty but does the job. Though using Mail::Sendmail is a nice Perl only solution.
        However, if you want the cron line to mail you then I think it's possible but messy but IMHO there is no need for this. Don't worry about cron you can trust it. BTW if you are using a commercial ?nix then it is supported by the OS vendor.
        I've used it for ten years on most ?nix flavours and the only problems were of my own devising
(atl: include type of failure) RE: cronjobs and perl
by atl (Pilgrim) on Sep 18, 2000 at 15:05 UTC
    Ahem, I´d really like to help, but without any hint on the type of failure, it will be impossible. Surely you´ll agree that the possibilities for failure are countless, even on a properly configured system (let alone a bad or BOFH system;
    <BOFH>
    think of it: configure cron to run with a chroot environment, the users will never figure out what´s the problem! {veg}
    </BOFH>
    ).

    To aid your search for information:

    • There should be a mail, sent to root, after the failure of one or more cron jobs. Look there for exit codes and/or messages.
    • Rewrite your script to send a message to the syslog (or a file in /tmp, use a unique name including a timestamp) first thing (even before useing libraries. If you get the message, your script did start up and found a perl interpreter, so put in new debug messages. Otherwise, your perl installation might not be in the search path.

    If you got more details, post a followup. We´ll be here :-).

    Have fun ...

    Andreas

RE: cronjobs and perl
by Jouke (Curate) on Sep 18, 2000 at 13:08 UTC
    It's probably a matter of permissions. You don't have the same permissions that the 'cron' user has. If the script itself is executable for other users, also check if the files that your script uses are accessible too...

    HTH,

    Jouke Visser, Perl 'Adept'
      Typically cron jobs are run as the user that set up the job. If I (fastolfe) run "crontab -e", I'm opening the crontab file for my user. These things will be run as myself at the appropriate times, so there shouldn't (tm) be any ownership/permissions issues here. I suspect it's a problem with his PATH or other environment setting.
Re: cronjobs and perl
by ZZamboni (Curate) on Sep 19, 2000 at 00:08 UTC
    Apart from what others have said, if you are using libraries from non-standard places, you may have to set the PERLLIB or PERL5LIB environment library before calling your script in the crontab entry (or add the appropriate use lib pragma to your script), like this:
    * * * * * PERL5LIB=/your/lib/dir /your/script.pl

    --ZZamboni

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-11-30 03:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?