문제

Cronjob에서 다음 스크립트를 실행하고 있습니다 ...

cd /etc/parselog/
php run_all.php >/dev/null

다음과 같은 오류가 발생합니다.

[05-May-2009 20:30:12] PHP Warning:  PHP Startup: Unable to load dynamic library './pdo.so' - ./pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0
[05-May-2009 20:30:12] PHP Warning:  PHP Startup: Unable to load dynamic library './mysql.so' - ./mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
[05-May-2009 20:30:12] PHP Warning:  PHP Startup: Unable to load dynamic library './mysql.so' - ./mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
[05-May-2009 20:30:12] PHP Warning:  PHP Startup: Unable to load dynamic library './mysqli.so' - ./mysqli.so: cannot open shared object file: No such file or directory in Unknown on line 0
[05-May-2009 20:30:12] PHP Warning:  PHP Startup: Unable to load dynamic library './odbc.so' - ./odbc.so: cannot open shared object file: No such file or directory in Unknown on line 0
[05-May-2009 20:30:12] PHP Warning:  PHP Startup: Unable to load dynamic library './pdo.so' - ./pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0
[05-May-2009 20:30:12] PHP Warning:  PHP Startup: Unable to load dynamic library './pdo_mysql.so' - ./pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
[05-May-2009 20:30:12] PHP Warning:  PHP Startup: Unable to load dynamic library './pdo_odbc.so' - ./pdo_odbc.so: cannot open shared object file: No such file or directory in Unknown on line 0
[05-May-2009 20:30:12] PHP Warning:  PHP Startup: Unable to load dynamic library './pdo_sqlite.so' - ./pdo_sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0
[05-May-2009 20:30:12] PHP Fatal error:  Call to undefined function mysql_connect() in /etc/parselog/stats_downloads.php on line 5

그러나 명령 줄에서 동일한 스크립트를 실행하면 로그인이 오류없이 완벽하게 작동합니다.

이것은 프롬프트에서 내 $ 경로 문자열입니다.

$PATH = /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin

아이디어 나 제안이 있습니까? 나는 cronjob을 실행할 때 Lib 경로 나 포함 된 것이 없다고 확신합니다. 나는 심지어 정확한 경로를 추가하려고 시도했습니다

도움이 되었습니까?

해결책

Tip 1: Ensure you have exactly the same $PATH in the cron job:

cd /etc/parselog/
export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
php run_all.php >/dev/null

Tip 2: Make sure all other environment variables match as well. Dump the environment with the command env, and add the corresponding exports to your cron job.

다른 팁

Generally when something fails during cron but runs on the command line it's permissions, working directory, or environment variables.

It looks like the php executable itself isn't loading the libraries, the problem might not be in your script.

When you run a script in a cron job, it is run in a limited shell with very few environment variables set. From your errors, it looks like it may be the LD_LIBRARY_PATH that needs to be set as the errors pertain to a bunch of shared libraries, but that is just a guess. It looks like the proper library paths for PHP are not being set up correctly in the cron script.

You can capture the environment used when running the cron script by adding the env command to the script and capturing the output. Compare this to the env output at the prompt and look for variations. Most likely they will be from commands issued in either your local or system profile or bashrc (or maybe even .login) files that set up library paths. I'd specifically look for paths and variables related to PHP since that seems to be your issue.

I had to deal with this issue several times on my last project and the basic solution is to:

  1. determine the minimum environment needed to execute the script
  2. create a short script that sets up the desired environment
  3. add a call to the script from item 2 in the script launching your applications so that the environment is set up properly.
  4. Test thoroughly to make sure you didn't miss anything :-).

When a cron job is run from the users crontab it is executed as that user. It does not however source any files in the users home directory like their .profile, .cshrc, or .bashrc or any other file. If you need cron to source (read) any file that your script will need you should do it from the script cron is calling. Setting paths, sourcing files, setting environment variables, etc.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top