PDA

View Full Version : cron job


mario.dobnig
05-26-2001, 10:28 AM
hi,

does anyone know how to make a cron job with php?

thanks, mario dobnig
http://go4xml.com

Maverick
05-26-2001, 12:39 PM
You do it with PHP almost exactly the same way you do it with Perl, except that you need to add the path to PHP in the cronfile. So in Perl it's:

MAILTO=webmaster@yourdomain.com
* * * * * /server/path/to/script.cgi

In PHP:

MAILTO=webmaster@yourdomain.com
* * * * * /usr/local/bin/php /server/path/to/script.php

digitalulmer
12-15-2003, 04:45 PM
My head is spinning. I have followed these directions to do a cron job on a PHP script but I keep getting the error:

Status: 404

Content-type: text/html

X-Powered-By: PHP/4.3.2



No input file specified.

If I place -q between the PHP path and the file path then I get the same error minus the first three lines. So just:

No input file specified.

I've tried moving the file inside and outside the web tree with no change. I don't have any includes in the PHP file. My cron file simply looks like this:

MAILTO=my_email@my_domain.com
* * * * * /usr/local/bin/php /big/dom/xmy_domain/file.php

Does anybody have any ideas on why it can't find my file?

Monty
12-15-2003, 04:53 PM
there appears to be an extra space after php, have you tried it as below?

MAILTO=webmaster@yourdomain.com
* * * * * /usr/local/bin/php/server/path/to/script.php

JoeRT
12-15-2003, 04:53 PM
MAILTO=my_email@my_domain.com
* * * * * /usr/local/bin/php /big/dom/xmy_domain/file.php

Does anybody have any ideas on why it can't find my file?
You can't run php files outside of the www directory. So the complete path is probably /big/dom/xmy_domain/www/file.php. If not, you need to move the file into the www directory.


Joe Torsitano
http://www.weatherforyou.com/images/logo/logo03small.jpg

JoeRT
12-15-2003, 04:56 PM
there appears to be an extra space after php
That space needs to be there. It's saying to use php (/usr/local/bin/php) to run /big/dom/xmy_domain/www/file.php


Joe Torsitano
http://www.weatherforyou.com/images/logo/logo03small.jpg

Terra
12-15-2003, 05:15 PM
You can't run php files outside of the www directory
That is only true for when you are calling the PHP files via the embedded Apache/PHP module...

If you run them via the PHP binary, then you can pretty much run them from anywhere within your XDOM directory space... The PHP binary has the same execution characteristics as running Perl scripts via it's binary...

--
Terra
--clarity--
FutureQuest

digitalulmer
12-15-2003, 06:11 PM
I'm on Futurequest. I have tried it with the PHP script in the www folder and still had the same reusult.

Could the error be saying its not finding the php.ini file in the usr/local/bin/php path? My PHP script is definitely there so I just don't get why its telling me the input file is not specified.

Thanks for the effort.

-chris

Terra
12-15-2003, 06:24 PM
What happens when you login directly to the command line via SSH and run it manually?

--
Terra
sysAdmin
FutureQuest

digitalulmer
12-15-2003, 07:04 PM
I don't have much knowledge of the command line. Would I just type in the same line I have in the Cron file? Could you give me an example of how to run it so I can get the answer?

Thanks,

chris

DB
01-08-2004, 05:30 PM
FWIW, this format has always worked for me:

MAILTO=webmaster@yourdomain.com
* * * * * /usr/local/bin/php -q /big/dom/xyourdomain/www/script.php

Kevin
01-08-2004, 05:36 PM
Originally posted by digitalulmer:
I don't have much knowledge of the command line. Would I just type in the same line I have in the Cron file? Could you give me an example of how to run it so I can get the answer?

Thanks,

chris
Chris,
You would run the same command as in the cron file but without the schedueling info at the beginning of the line.

--Kevin

digitalulmer
01-08-2004, 07:02 PM
Thanks for following-up on this. I typed in:

/usr/local/bin/php -q /big/dom/xyourdomain/www/script.php


at the comment line while logged into telnet and it ran my script successfully.

Still no luck running it on the crontab.

Could there be something with file permissions

DB
01-09-2004, 11:16 AM
This may be a long shot, but check to see if there are any spaces or new lines after the closing PHP statement (IOWs, the very last line should end with "?>"). Anything after the close statement is treated as output, in the case of a cronjob it would have nowhere to go unless an input file were specified. Likewise, there should be nothing before the opening PHP statement and any print or echo statements should be directed to a file or e-mail.

digitalulmer
01-09-2004, 12:18 PM
Well I really thought you were on to something but still no luck.

I trimed the script down to 4 lines of code. Open a connection to the database and enter some data into a table. No additional lines anywhere. The script runs fine at the command line.

Do I need to specify an input file?

Do you have an example script I could try and see if it works?

Thanks for the ideas,

Chris

DB
01-09-2004, 12:36 PM
You shouldn't need to specify an input file, given that the script shouldn't have any output other than to the database.

Maybe try running a script that does nothing other than creating a file called "it_worked.txt" and see what happens. Or if you want to e-mail me (webmaster@diamond-back.com), I'll see what I can come up with to send back.

FWIW, the first time I tried running a PHP script as a cronjob it was a PITA, after finally getting the first one to work the rest have been easy.

Jarrod
01-09-2004, 12:55 PM
For a simple PHP script you could try:

<?
print phpinfo();
?>

But if the command line is working and you are using the exact same command line in your cronjob your existing script should also work. Are you editing the cronjobs directly from the command line with crontab -e or are you editing a text file. If you are editing a text file, you need to make sure you replacing the existing cron with the latest version. See step 4 in the help (http://www.aota.net/Script_Installation_Tips/cronhelp.php4) file for details on how to do this.

digitalulmer
01-09-2004, 02:48 PM
I gave it another go with the create text file script as well as open a text file and write into it. Again I tested the scipt file first at the command line and it worked. But still when I run the scipt as a cronjob I get the error "No input file specified". I gotta say you guys have been great with coming up with ideas but it just doesn't want to work.

I've followed every instruction in the help file, I do use crontab -r to remove the file. I don't feel like its anything in the steps I'm taking.

The error seems to me like it doesn't find my scipt file...I just don't know how that can be.

Chris

pinxit
02-05-2004, 09:03 AM
I had the same problems, but finally found that one should use the absolute path to the crontab file, when registering it. So use

crontab /path/to/your/crontab-file

instead of

crontab crontab-file

This worked for me.

Gr., Wilbert

digitalulmer
02-10-2004, 02:36 PM
When I get the error, "No input file specified", it is coming in an email sent to me from the CRON DAEMON. I believe my cron file is registering correctly and I am using the absolute path to register the cron file.

Does anyone have a perl script example I could use to test the cron. I thought I saw in a different thread that with a perl script I would just need to have the script in the cgi-bin for it to run and would not have to reference anything but that script in the cronfile. I'm curious to see if I can get something to work.

Thanks,

Chris

squillo
02-18-2004, 06:10 AM
Here's a working example taken from a perl script that is called by a cron job.

The datafix.pl script:

#!/usr/local/bin/perl

if ((-M "/big/dom/xdomain/cgi-bin/somefile1.txt") > (-M "/big/dom/xdomain/cgi-bin/somefile2.txt"))
{ print "This is the server: It looks like somefile1 is older than somefile2."; }

And the cronfile.txt:

MAILTO=scriptjobs@domain.net
30 8-22 * * * /usr/local/bin/perl "/big/dom/xdomain/cgi-bin/datafix.pl"

My problem is, when I altered the above cronjob to work with a php script I get blank emails from the cron even though there's nothing to report. When I ran the Perl script, it only sent me an email when the If clause was true. The contents of my new cronfile.txt is like this:

MAILTO=scriptjobs@domain.net
30 8-22 * * * /usr/local/bin/php -q "/big/dom/xdomain/cgi-bin/datafix.php"

cheers,
squillo