cron job Extension /path/to/script not found error
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
cron job Extension /path/to/script not found error
I keep getting this error when I run a script. I have a script named something like script.sh and run it by typing /home/user_name/script.sh and it tells me Extension '/home/user/script.sh' not present.
I try to run the cron also by using the command php /home/user/scripts/my_script.php and that gives me the error
<br />
<b>Fatal error</b>: Class 'PDO' not found in
<b>/home/user/public_html/inc/db.php</b> on line <b>23</b><br />
line 23 of db.php
$dbh = new PDO('mysql:host='.$mysqlServer.';dbname='.$mDB, $mysqlUserName, $mysqlPassword);
It seems like running the second command works better than the first, but neither work. Please help.
I keep getting this error when I run a script. I have a script named something like script.sh and run it by typing /home/user_name/script.sh and it tells me Extension '/home/user/script.sh' not present.
I try to run the cron also by using the command php /home/user/scripts/my_script.php and that gives me the error
<br />
<b>Fatal error</b>: Class 'PDO' not found in
<b>/home/user/public_html/inc/db.php</b> on line <b>23</b><br />
line 23 of db.php
$dbh = new PDO('mysql:host='.$mysqlServer.';dbname='.$mDB, $mysqlUserName, $mysqlPassword);
It seems like running the second command works better than the first, but neither work. Please help.
The problem could be that it cannot find one of the commands within /home/user_name/script.sh. Check to see if you give the full path for all of the commands within the script.
I don't think the executing shell command is my biggest problem. I can get around that by using the second command, php -f /home/user/scripts/my_script.php.
My problem is that when I do it from cron, I get the error of Class PDO not found. If I execute the same script from the shell (SSH), it works fine. Also, it works fine if I execute it from the web. The only problem is with cron.
The server guys assured my pdo mysql is installed in the cli version of php, but it's not working for some reason.
I don't think the executing shell command is my biggest problem. I can get around that by using the second command, php -f /home/user/scripts/my_script.php.
My problem is that when I do it from cron, I get the error of Class PDO not found. If I execute the same script from the shell (SSH), it works fine. Also, it works fine if I execute it from the web. The only problem is with cron.
The server guys assured my pdo mysql is installed in the cli version of php, but it's not working for some reason.
What you are describing is a very common question on linuxquestions. The cause is that the PATH for cron is very skimpy. So programs that are found on the command line are not found on the cron PATH. The solution is to give the full path for every command executed under the cron daemon. Your only command that I see missing the full path is the php compiler. So try giving the full path for the php compiler in your script.
Quote:
Originally Posted by mts7
My problem is that when I do it from cron, I get the error of Class PDO not found. If I execute the same script from the shell (SSH), it works fine. Also, it works fine if I execute it from the web. The only problem is with cron.
The server guys assured my pdo mysql is installed in the cli version of php, but it's not working for some reason.
You possibly have the same problem within your php code. If your php code is making dynamic calls to programs within the PATH then you can have the calls working on your command line PATH and not on your cron PATH. I doubt that you can create complete command paths within object oriented code. Instead you should try to set up your cron PATH to include the PATH to your pdo mysql (if that makes sense?).
So I suggest that at the command line you use this command:
echo $PATH
to find out what your PATH is. Then take any mysql or php libraries in your command line PATH and add them to your cron PATH by adding a PATH command as the first command in your cron script. Something like:
you can edit a crontab file to include variable to set the env. The main config file is normally /etc/crontab.
On a default RedHat install, the crontab will look something like this:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.