LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 04-18-2011, 01:31 AM   #1
qwertyjjj
Senior Member
 
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013

Rep: Reputation: 30
crontab not running php script


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?
 
Old 04-18-2011, 01:34 AM   #2
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
Maybe it is a permission thing, so take a look at those
make sure they are executable!

after you made your cronjob file, did you use this command?
Code:
crontab filename_of_cronjob
 
Old 04-18-2011, 01:37 AM   #3
qwertyjjj
Senior Member
 
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by brownie_cookie View Post
Maybe it is a permission thing, so take a look at those
make sure they are executable!

after you made your cronjob file, did you use this command?
Code:
crontab filename_of_cronjob
Isn't it dangerous to make a file in the www folder executable?
 
Old 04-18-2011, 01:45 AM   #4
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
i don't know but a script must be made executable in order to let it working.
But did you do that command?
If not, first try that
 
Old 04-18-2011, 01:48 AM   #5
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
and maybe try with your php command the option -f
 
Old 04-18-2011, 02:26 AM   #6
qwertyjjj
Senior Member
 
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013

Original Poster
Rep: Reputation: 30
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?
 
Old 04-18-2011, 02:41 AM   #7
qwertyjjj
Senior Member
 
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013

Original Poster
Rep: Reputation: 30
FFR, I have followed this:

Code:
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
 
Old 04-18-2011, 02:42 AM   #8
qwertyjjj
Senior Member
 
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013

Original Poster
Rep: Reputation: 30
Although when I try to run the crontab script it says:
Code:
[root html]# crontab crontab
crontab: No such file or directory
[root html]#
what does the crontab line do?
 
Old 04-18-2011, 02:47 AM   #9
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
Code:
man crontab
Quote:
NAME
crontab - maintain crontab files for individual users (ISC Cron V4.1)

SYNOPSIS
crontab [-u user] file
crontab [-u user] [-l | -r | -e] [-i] [-s]

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.
 
Old 04-18-2011, 11:48 AM   #10
lrtward
Member
 
Registered: Feb 2011
Distribution: CentOS, Ubuntu
Posts: 97

Rep: Reputation: 9
I run a php script each night from cron and here is how my setup varies from yours.

I do NOT run "php scriptname" in cron, I just run the script:
Quote:
5 0 * * * /root/scripts/myscript
The first line in my script indicates that it is a php script:
Quote:
# head /root/scripts/myscript
#!/usr/bin/php -q
<?php
$today = date('Y-m-d');
....
?>
My script is executable, but only by root; dunno if that matters, I've never tried changing the perms because it works as is:
Quote:
# ls -l /root/scripts/myscript
-rwx------ 1 root root 2614 Mar 17 14:54 /root/scripts/myscript
 
Old 04-18-2011, 12:27 PM   #11
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
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/ ?
 
Old 04-18-2011, 08:31 PM   #12
themanwhowas
Member
 
Registered: Nov 2005
Distribution: CentOS 5, Fedora 23
Posts: 218

Rep: Reputation: 29
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.
 
Old 04-19-2011, 12:31 AM   #13
hks1233
Member
 
Registered: Nov 2010
Posts: 30

Rep: Reputation: 1
Make your crontab entry like this


30 */3 * * * /installation_path/bin/php -q /var/www/html/mkimages.php
0 */3 * * * /installation_path/bin/php -q /var/www/html/import_historic_data.php
 
  


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
Crontab not running script j8177e5 Linux - Newbie 2 12-21-2010 08:54 AM
[SOLVED] Crontab Script Not Running th1bill Ubuntu 4 12-10-2010 03:49 PM
crontab not running script sunlinux Linux - Newbie 5 05-18-2010 06:21 AM
Shell Script not Running from Crontab venkatramanj SUSE / openSUSE 3 01-13-2010 05:15 AM
Running a script with crontab. glore2002 Slackware 3 06-05-2008 08:48 PM

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

All times are GMT -5. The time now is 03:13 AM.

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