LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-20-2008, 05:02 PM   #1
mts7
LQ Newbie
 
Registered: Mar 2008
Distribution: CentOS 4.5
Posts: 12

Rep: Reputation: 0
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.
 
Old 03-20-2008, 05:27 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,336

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
Quote:
Originally Posted by mts7 View Post
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.

----------------------
Steve Stites
 
Old 03-20-2008, 05:34 PM   #3
mts7
LQ Newbie
 
Registered: Mar 2008
Distribution: CentOS 4.5
Posts: 12

Original Poster
Rep: Reputation: 0
I have a comment as the first line, then I have <?php // my code ?> after that.
 
Old 03-20-2008, 05:36 PM   #4
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,336

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
Quote:
Originally Posted by mts7 View Post
I have a comment as the first line, then I have <?php // my code ?> after that.
Try giving it a full path to php.

----------------
Steve Stites
 
Old 03-20-2008, 05:47 PM   #5
mts7
LQ Newbie
 
Registered: Mar 2008
Distribution: CentOS 4.5
Posts: 12

Original Poster
Rep: Reputation: 0
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.
 
Old 03-20-2008, 06:12 PM   #6
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,336

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
Quote:
Originally Posted by mts7 View Post
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 View Post

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:

PATH=$PATH:/usr/mysql/xxx:/usr/php/yyy


----------------------
Steve Stites
 
Old 03-20-2008, 10:05 PM   #7
prad77
Member
 
Registered: Mar 2008
Posts: 101

Rep: Reputation: 15
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:

root@pingu # cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily

If the env variables are set properly , libraries will be visible to the executing script.

Fedora Development

Last edited by prad77; 04-17-2008 at 03:18 AM.
 
Old 03-20-2008, 10:56 PM   #8
mts7
LQ Newbie
 
Registered: Mar 2008
Distribution: CentOS 4.5
Posts: 12

Original Poster
Rep: Reputation: 0
I tried the suggestion about using the full path to php and it seems to be working now. Wow. Such an easy fix took hours and hours to do.

Thank you so much for your help!!!

I changed the command from php /home/... to /usr/local/bin/php /home/... and now it is working just fine. :-D
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
script does not run in cron job kashyapvirgo Linux - General 8 03-20-2007 10:55 AM
Bash script and cron job rust8y Linux - General 2 07-08-2006 07:45 AM
Cron Job with a Script bravored Linux - General 4 08-05-2005 10:27 AM
script not running as a cron job sanjith11 Programming 5 11-23-2004 08:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration