LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-21-2009, 10:18 AM   #1
bar338
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Rep: Reputation: 0
Executing PHP script in crontab (include path problems)


I'm attempting to run a script by launching it daily from the crontab. The script works fine when I call it from the browser. However, whenever the crontab attempts to initiate the script it gets an error.
Warning: require_once(/pathtomyscript/includes/co… failed to open stream: No such file or directory in /pathtomyscript/cron.php

Apparently the crontab has difficulties with executing scripts that contain relative paths. To fix this I tried changing the path to an absolute path like /home/www/public_html/pathtoscript/inclu… however this gives me the error of illegal include. How should I control my include paths so that they work with the cron tab?

The scripts are owned by root and the cronjob is executed by root.

Thanks for your help.
 
Old 12-21-2009, 01:12 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927
When you say: "call it from the browser" ... is it actually meant to
be run under the control of apache? If so, why don't you point a
command-line browser like lynx, links or even curl or wget to it
from your cron-job?
Code:
13 17 * * * /usr/bin/lynx http://localhost/pathtomy/cron.php

Cheers,
Tink
 
Old 12-21-2009, 01:31 PM   #3
bar338
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Is this secure? Eventually I had planned on either moving the script to a non web-accessible location or password protecting it. The purpose of the script is to initiate a reindex of my database for my search engine.
 
Old 12-21-2009, 01:48 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927
As secure as your server/script.

Which RDBMS are you using, how complex is the PHP script?


Cheers
Tink
 
Old 12-21-2009, 02:11 PM   #5
bar338
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
I'm using mysql and the sphider php search engine. The indexing script has some degree of complexity.

Shouldn't I be able to adjust the include path so that the crontab located in
/etc/crontab
can call the index script in
/home/www/public_html/search/admin/cron_index.php
and the cron script can include a config file at:
/home/www/public_html/search/includes/config.conf

The script does not have to be accessible to anything other than the crontab. It is in the search directory just to keep it in close proximity with all the search elements.
 
Old 12-21-2009, 02:36 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927
My knowledge of PHP is quite limited, but my guess is that the paths
in the web-based interface are relative to the document root of the
site - which is why I suggested to access it via a browser. If you
modify the include directives within the php-scripts you may break
the behaviour of the web part. All this, of course, is just general
hand-waving, derived from my ideas on how things work, and why they
don't work from cron. I don't think that any include path you throw
at cron will fix the interdepencies of the scripts.


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
php include path puzzle prabhatsoni Linux - Software 6 10-08-2007 10:02 PM
Cron not Executing PHP script Badnoodles Linux - General 2 10-25-2006 04:56 PM
php include path khilari Linux - Newbie 1 05-31-2006 11:53 AM
Executing UNIX command from PHP script ckoniecny Programming 3 03-01-2006 10:42 PM
PHP Path include ..:eMa:.. Programming 4 09-25-2003 01:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:26 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