Linux - NewbieThis 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
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.
I have a crontab that is supposed to run 2 PHP scripts but they never run.
30 */3 * * * php /var/www/html/mkimages.php
0 */3 * * * php /var/www/html/import_historic_data.php
Both of these files are owned by root, is it a permissions thing?
How can I get get cron to run the files?
I get this error because the script has relative paths:
BNZL.L CPI.L JpGraph Error: 25107 Can't write to file "http://www.linuxquestions.org/questions/images/BNZL-CPI.jpg".
Is it better to change the script or is there a way of running the crontab in the var/www/ foldeR?
ALternatively, how can I get the crontab to call a webpage instead and run the script from a URL call?
Be sure your "script.php" has the necessary permissions to be executable ("chmod 755 script.php"). Now you are all set!
Apache module
If your PHP is installed using the Apache module, the approach is a little different. First, you need access to Lynx (Lynx Browser for more information). Lynx is a small web browser, generally available on Unix and Linux. Running your PHP script will not require you to add any additional lines. You simply have to edit your /etc/crontab file and add the following line:
* * * * * lynx -dump http://www.somedomain.com/cron.php
Please note that in general, you have to specify the entire URL (with "http://" and so on). But depending on your Lynx's configuration, the URL might be relative; I suggest always using the absolute reference as in my example above - it always works. Again execute the following from the command line:
Seems to work and scripts do not need to be esxecutable
DESCRIPTION
Crontab is the program used to install, deinstall or list the tables used to drive the cron(8) daemon in ISC
Cron. Each user can have their own crontab, and though these are files in /var/spool/ , they are not intended
to be edited directly. For SELinux in mls mode can be even more crontabs - for each range. For more see
selinux(8).
If the cron.allow file exists, then you must be listed therein in order to be allowed to use this command. If
the cron.allow file does not exist but the cron.deny file does exist, then you must not be listed in the
cron.deny file in order to use this command. If neither of these files exists, only the super user will be
allowed to use this command.
if you get that error you posted, mayeb the filename is incorrect..
do a
Code:
ll
and see if you (accidentially) have used an extension (like crontab.txt) and change if needed
Last edited by brownie_cookie; 04-18-2011 at 02:48 AM.
FWIW I run PHP scripts from cron and do it the same way lrtward does except the scripts are neither owned by nor run as root.
I think maybe you are confusing running PHP as an Apache module with just using it as a scripting language. Are your PHP scripts being used as part of pages that Apache is serving? If not, then why are they in /var/www/html/ ?
I second what arizonagroovejet says. You can make a php script in your home directory and it will run just the same. You only need it in www if you want it to run from a browser.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.