Perl script works but not via CRON

前端 未结 6 1936
太阳男子
太阳男子 2020-12-11 11:56

I have a perl script (which syncs delicious to wp) which:

  1. runs via the shell but
  2. does not run via cron (and i dont get an error)

The o

相关标签:
6条回答
  • 2020-12-11 12:29

    I suggest looking at my answer to How to simulate the environment cron executes a script with?

    This is an similar Jonathan's answer but goes a bit further.

    0 讨论(0)
  • 2020-12-11 12:29

    Based on your crontab, and depending on your installation, the problem might be the "perl". As others note the environment, particularly the $PATH variable, is different for cron. perl may not be in the path so you need to put the full path to perl in the cron command.

    You can determine the path with the command $ type perl

    0 讨论(0)
  • 2020-12-11 12:31
     If the perl script runs fine manually, but not from crontab, then
     there is some environment path needed by the some package that is not
     getting through `cron`. Run your command as follows:
     suppose your cron entry like:
    
    * 13 * * * /usr/bin/perl /home/username/public_html/cron.pl >/dev/null 2>&1
    
     env - /home/username/public_html/cron.pl
    
     The output will show you the missing package. export that package path in
     $PATH variables
    
    0 讨论(0)
  • 2020-12-11 12:39

    The difference between a cron job and a job run from the shell is 'environment'. The primary difference is that your profile and the like are not run for a cron job, so any environment variables you have set in your normal shell environment are not set the same in the cron environment - no extensions to PATH, no environment variables identifying where Delicious and/or WP are hosted, etc.

    Suggestion: create a cron job that simply reports the environment to a known file:

    env > /home/27632/tmp/env.27632
    

    Then see what is set in your own shell environment in comparison. Chances are, that will reveal the trouble.

    Failing that, other environmental differences are that a cron job has no terminal, and has /dev/null for input and output - so interactive stuff does not work well.

    0 讨论(0)
  • 2020-12-11 12:47

    it seems the problem is not in running perl, but locating the Config library

    you should try:

    perl -e "print @INC"

    and run a similar perl script in cron, and read the output

    it possible that they differ

    0 讨论(0)
  • 2020-12-11 12:51

    I run into the same problem ...

    Perl script works but not via CRON => error: "perl: command not found"

    ... after an update from Plesk 12.0 to Plesk 12.5. But the existing answers were not very helpful for me.

    It took some time, but than I found this thread in the Odin forum which helps me: https://talk.plesk.com/threads/scheduled-tasks-always-fail.331821/

    They suggest the following:

    /usr/local/psa/bin/server_pref -u -crontab-secure-shell ""
    

    That deletes in the /var/spool/cron/crontabs files the line:

    SHELL="/opt/psa/bin/chrootsh"
    

    After that, my cron jobs run with out any error.

    (Ubuntu 14.04 with Plesk 12.5)

    0 讨论(0)
提交回复
热议问题