PHP errors on cronjob, works great when prompted

I am running the following script on cronjob ...

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

and I get the following errors:

[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

However, when I run the same script from the command line, the login works without errors.

This is the $ PATH line at the prompt:

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

Any ideas or suggestions? I am sure that when running cronjob it does not have a lib path or anything in it. I even tried to add the exact path

+3
source share
4 answers

Tip 1: Make sure the cron job has exactly the same $ PATH:

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 are the same. Dump the environment using the command envand add the appropriate export to your cron job.

+5
source

, - cron, , , .

, php , script.

+3

script cron, . , LD_LIBRARY_PATH , , . , PHP cron script.

, cron script, env script . env . , , , , bashrc (, , .login), . , PHP, , , .

, :

  • , script
  • script, .
  • script 2 script, , .
  • , : -).
+1
source

When a cron job is started from the crontab user, it runs as that user. However, it does not contain any files in the users home directory, such as their .profile, .cshrc or .bashrc or any other file. If you need cron to source (read) any file you need a script for, you have to do it from the script that calls cron. Setting paths, searching for files, setting environment variables, etc.

0
source

Source: https://habr.com/ru/post/1707711/


All Articles