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

Hey Monks!!! I'm trying to finish a script I made, but I've been fighting with a problem for the last few days.
*some script* #Here I run a external script, that needs to be executed as bibatch us +er (sudo -u bibatch) system ("/opt/progressor/PRODEHPT/TECHTEL/PROCESO_COBRANZAS.sh");
So, if I run that in console (pagos.pl is my script, that calls the other script inside):

sudo -u bibatch /usr/bin/perl /home/bibatch/Pagos/scripts/pagos.pl

It runs like a charm, executes my script and then it calls the other one, BUT, if I put that line in crontab, it doesn't run:

minute hour * * * "sudo -u bibatch /usr/bin/perl /home/bibatch/Pagos/scripts/pagos.pl"

Neither my script (pagos.pl) nor the inside one I call (PROCESO_COBRANZAS.sh). Any ideas? Thanks!

Replies are listed 'Best First'.
Re: Perl script in crontab
by roboticus (Chancellor) on Nov 20, 2010 at 05:03 UTC

    HocusPocus:

    First, crontab doesn't invoke a shell for you, so your environment variables, paths, etc. aren't going to be set up the way you want. That may be part of your problem.

    However, what prompted me to post is the use of sudo in your crontab. Why not just use sudo to put the job in the proper user's (bibatch) crontab? Then things would be a bit less Rube Goldbergesqueified.

    ...roboticus

      I use sudo to call the script pagos.pl, because when then calls PROCESO_COBRANZAS.sh it runs ok (because that scripts NEEDS to be executed as bibatch), and, because I need that pagos.pl send emails as bibatch. I'm using bibatch's crontab.
Re: Perl script in crontab
by JavaFan (Canon) on Nov 20, 2010 at 20:32 UTC
    Drop the quotes. Furthermore, cron ought to email you - it should have told you what is wrong. Do you have set up your cron correctly?
Re: Perl script in crontab
by Anonymous Monk on Nov 20, 2010 at 21:42 UTC
    Hi,

    We did something like this -

        minute hour * * * use setup_file; sudo -u bibatch /usr/bin/perl /home/bibatch/Pagos/scripts/pagos.pl

    depending on which variety of shell is being used.

    It may not be pretty, but it worked.

    J.C.


      No, no, no, it wasn't 'use', it was 'source' or '.'.

      J.C.