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

Hi

i need help for perl script.

My crob job set as following, i tested on command list working fine. date >> /tmp/mycron.log is running but perl script don't run.

0,5,10,15,20,25,30,35,40,45,50,55 * * * * date >> /tmp/mycron.log; /usr/bin/perl /share/script/Test/report.pl

cron log:

Jul 19 12:30:01 Danny CROND[9154]: (root) CMD (date >> tmp/mycron.log; + perl /share/script/Test/report.pl /share/script/Test/file/ltm_all_no +n_prod) Jul 19 12:30:01 Danny CROND[9155]: (root) CMD (/usr/lib64/sa/sa1 1 1) Jul 19 12:40:01 Danny CROND[9200]: (root) CMD (/usr/lib64/sa/sa1 1 1) Jul 19 12:44:05 Danny crontab[9221]: (root) LIST (root) Jul 19 12:45:01 Danny CROND[9228]: (root) CMD (date >> tmp/mycron.log; + perl /share/script/Test/report.pl /share/script/Test/file/ltm_all_no +n_prod) Jul 19 12:45:30 Danny crontab[9249]: (root) BEGIN EDIT (root) Jul 19 12:46:11 Danny crontab[9249]: (root) REPLACE (root) Jul 19 12:46:11 Danny crontab[9249]: (root) END EDIT (root) Jul 19 12:46:43 Danny crontab[9265]: (root) LIST (root) Jul 19 12:47:01 Danny crond[1403]: (root) RELOAD (/var/spool/cron/root +) Jul 19 12:47:01 Danny CROND[9271]: (root) CMD (date >> /tmp/mycron.log +; perl /share/script/Test/report.pl /share/script/Test/file/ltm_all_n +on_prod) Jul 19 12:48:14 Danny crontab[9293]: (root) BEGIN EDIT (root) Jul 19 12:48:21 Danny crontab[9293]: (root) REPLACE (root) Jul 19 12:48:21 Danny crontab[9293]: (root) END EDIT (root) Jul 19 12:49:01 Danny crond[1403]: (root) RELOAD (/var/spool/cron/root +) Jul 19 12:49:01 Danny CROND[9309]: (root) CMD (date >> /tmp/mycron.log +; perl /share/script/Test/report.pl /share/script/Test/file/ltm_all_n +on_prod) Jul 19 12:50:01 Danny CROND[9363]: (root) CMD (/usr/lib64/sa/sa1 1 1) Jul 19 12:52:22 Danny crontab[9384]: (root) BEGIN EDIT (root) Jul 19 12:52:32 Danny crontab[9384]: (root) REPLACE (root) Jul 19 12:52:32 Danny crontab[9384]: (root) END EDIT (root) Jul 19 12:53:01 Danny crond[1403]: (root) RELOAD (/var/spool/cron/root +) Jul 19 12:53:01 Danny CROND[9391]: (root) CMD (date >> /tmp/mycron.log +; perl /share/script/Test/report.pl /share/script/Test/file/ltm_all_n +on_prod)

Replies are listed 'Best First'.
Re: Perl cron job not running
by haukex (Archbishop) on Jul 20, 2016 at 07:25 UTC

    Hi chefchanyu,

    A few more diagnostics would be helpful.

    I'm assuming /tmp/mycron.log gets updated? How exactly have you determined that your script isn't run?

    Why is there a difference between the crontab entry you showed and the cron command from the logs? What happens when you try to run the exact crontab entry from the command line? ("date >> /tmp/mycron.log; perl /share/script/Test/report.pl /share/script/Test/file/ltm_all_non_prod")

    Has cron sent you any e-mails? You can test this with a crontab entry that simply does "echo Hello", your root user should receive an e-mail, assuming that's been configured correctly. Look into whether your system has local mail delivery configured and at cron's MAILTO option (more detail in crontab(5)).

    Hope this helps,
    -- Hauke D

Re: Perl cron job not running
by soonix (Chancellor) on Jul 20, 2016 at 11:01 UTC
    recently, I stumbled over the tip to have a cron job execute set and id (both with no parameters). This will show you cron's environment and user information, so you can either compare, or run your test using su and env.
Re: Perl cron job not running
by RonW (Parson) on Jul 20, 2016 at 00:23 UTC

    Did you run your program as an "ordinary", non-privileged user? (Preferably not your own user account you use for code development.)

    Have you tried running it with

    sudo -u cron /usr/bin/perl /share/script/Test/report.pl /share/script/Test/file/ltm_all_non_prod
      i use root user to run this script
Re: Perl cron job not running
by Anonymous Monk on Jul 19, 2016 at 23:57 UTC

      No the script did not run.

        If i were you I would replace the "command" with a single  /path/to/icrons.sh or icrons.pl, and do all your file redirections and multiple commands in that file
Re: Perl cron job not running
by Marshall (Canon) on Jul 20, 2016 at 01:25 UTC
    I am curious as to how you came up with this chron command? Looking at chron, there are 5 fields, you have 16. Also date >> /tmp/mycron.log; /usr/bin/perl /share/script/Test/report.pl seems suspect as that is not the normal command line syntax for redirection. What is "date"? /usr/bin/perl /share/script/Test/report.pl >> /tmp/mycron.log would seem more logical to me.
      Looking at chron, there are 5 fields, you have 16.

      The comma-separated list of minutes is the first field; plus 4 wildcard * makes 5.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

      date command just a out put of current time, just to prove cron did execute that line.

      report.pl itself will auto out put to it own log file. which already specify in the script.

Re: Perl cron job not running
by shmem (Chancellor) on Jul 20, 2016 at 08:37 UTC
    date >> /tmp/mycron.log; /usr/bin/perl /share/script/Test/report.pl

    Change the semicolon to && since cron executes only one command per entry:

    */5 * * * * date >> /tmp/mycron.log && /usr/bin/perl /share/script/Tes +t/report.pl

    update: wrong test - as haukex writes below, cron takes the rest of the line as one command.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

      Hi shmem,

      I guess there are different implementations of cron and it depends on that? The one on my system doesn't care about semicolons and executes multiple commands.

      Regards,
      -- Hauke D

        whipped up a cron line

        */1 * * * * root touch /tmp/foo; touch bar

        and checked /tmp - meh... bar was touched in /root of course :-P

        perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'