PHP Cron Job Problems

PHP Cron Job Problems

Posted by: zackwragg
Posted on: 2006-09-01 02:27:00

Hi all,

I am trying to set up a cron job to run every night. At the moment the line looks like this:

* 0 * * * /dh/cgi-system/php.cgi /home/username/domain.com/scripts/script.php

When this executes I get an email saying:

"No input file specified."

I have tried running the command on its own from the command line and it works fine. I have also tried this using /usr/local/bin/php instead but get the same outcome (works fine from command line but says "No input file specified" when run from cron).

Any ideas?

Re: PHP Cron Job Problems

Posted by: rlparker
Posted on: 2006-09-01 02:34:00

What happens if you run it from the web?

--rlparker


Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2006-09-01 02:39:00

Is /dh/cgi-system/php.cgi the full path? Cron will like the full path.
When you enter the crontab (crontab -e) make sure you add a newline at the end by pressing enter.
Also script.php should be executable which is what you probably have already.
You might also try a double 0 as a last ditch, over the top boys, attempt.


--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: zackwragg
Posted on: 2006-09-01 02:51:00

The script runs fine when run from the web. That is actually how I am having to run it at present.

I tihkn /dh/cgi-system/php.cgi is the full path. I got it from the Dreamhost wiki. I have also tried it using /usr/local/bin/php but no joy.

Script.php is 755 so shouldn't be a problem there. Have also tried a variety of times but not working. It is a couple of PHP scripts that I have not working also. Both have the same problems.

Fell foul of the newline problem at first but even with that it is still presenting problems.

Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2006-09-01 03:12:00

What is the wiki page you are looking at? Some of the wiki entries have been there a while and may not have had paths updated as DreamHost changed and evolved.


--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: zackwragg
Posted on: 2006-09-01 03:23:00

The page is:
http://wiki.dreamhost.com/index.php/Cron



Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2006-09-01 03:34:00

I tend to use /usr/local/bin/php and then make sure #!/usr/local/bin/php -q is the first line of the script.

So a full line would be:-

1,11,21,31,41,51 * * * * /usr/local/bin/php /home/username/domain/somefolder/reminders.php >/dev/null 2>&1

Noting the space after PHP (The dev/null just dumps any screen messages)

If you still get errors then it may be something wrong in your script.php which you may want to show here if you wish so others can check it over.


--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: zackwragg
Posted on: 2006-09-01 05:31:00

Thanks Norm,

I have tried using /usr/local/bin/php but it still gives me a "No input file found" message.

The script runs fine when run from the browser or from the command line so I don't think it is an issue with the script.

Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2006-09-01 05:46:00

It might be worth contacting support in that case with a link to this thread so they know what you have tried.

Have you tried setting up a simple crontab just to make sure that, that part of your account is okay?


--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: zackwragg
Posted on: 2006-09-01 05:51:00

No I haven't. I will give that one a try.

Thanks for all the help btw. Very much appreciated.

Re: PHP Cron Job Problems

Posted by: zackwragg
Posted on: 2006-09-01 06:26:00

OK, after some more playing I now have it picking up the file from the crontab. However, it is outputting the following error:

/bin/sh: line 1: 1
: ambiguous redirect

Script.php reads:

#!/usr/local/bin/php
<?php

$backupFile = '/home/darksummer/db_dumps/' . DB_NAME . date("Y-m-d-H-i-s") . '.gz';
$command = "/usr/bin/mysqldump --opt -h DB_SERVER -u DB_USER -pDB_PASSWORD DB_NAME | gzip > $backupFile";
system($command);
echo( '<h2>Database back-up completd successfully</h2>' );

?>

Any ideas on that one?

Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2006-09-01 07:00:00

Does that little dot before the gz need to be there?

And is the path for db_dumps okay?



Naaah forget the dot thing smile

--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: zackwragg
Posted on: 2006-09-01 07:04:00

Yes, it is appending the string. I have also tried the script with double quotes, but it makes no difference.

The crontab is not getting past line one as I have been trying it with some echos in there to debug it.

I have also tried removing the first line from script.php and it gives me the same outcome.

Re: PHP Cron Job Problems

Posted by: zackwragg
Posted on: 2006-09-01 07:05:00

Oh yeah, and the db_dumps path is fine. Like I say this has been running fine from the command line and in a browser.

Thanks

Re: PHP Cron Job Problems

Posted by: silkrooster
Posted on: 2006-09-01 20:20:00

If it helps I found the php.cgi file at /usr/local/dh/cgi-system/
Silk

My website

Re: PHP Cron Job Problems

Posted by: zackwragg
Posted on: 2006-09-05 04:19:00

The error I am currently getting is:

/bin/sh: line 1: 1
: ambiguous redirect

In script.php, the command I am sending to the shell is:

/usr/bin/mysqldump --opt -h mysql.domain.co.uk -u username -ppassword database_name | /bin/gzip > /home/username/db_dumps/database_name.sql.gz

Can anyone see anything in the shell command that would cause that error?

Thanks

Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2006-09-05 09:06:00

I decided to just set up the same cron job using your script. Hope you do not mind.

I get this back from crond, complete with your typo smile



X-Powered-By: PHP/4.4.2

Content-type: text/html



<h2>Database back-up completd successfully</h2>



So it certainly seems to run okay as you have laid it out.

The filename is as you expect

file2006-09-05-08-51-01.gz

I have just let the crontab run and I have had another OK and the gzipped file produced.


Sorry I cannot think of anything further to add. You are running the Bash shell? You have chmodded script.php to 755? You have added the extra linefeed to the crontab?

I have not tried under PHP5 but I would not see it being different.

Maybe one for support just in case there is a problem with tmp file permissions.


Sorry.



--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: zackwragg
Posted on: 2006-09-05 09:10:00

Thanks again for the help Norm. I think it is time to hit the support guys.

Re: PHP Cron Job Problems

Posted by: zackwragg
Posted on: 2006-09-05 09:22:00

Actually, I seem to have it working now. Once last ditch attempt before I was going to contact support and I found that the ambiguous redirect referred to the 2>&1 I had on the end of the line in my cron file. I removed that and now it is working.

Thanks for all the help. I appreciate it a lot.

Zack

Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2006-09-05 09:24:00

Post the final outcome if you can. I am intrigued to know what has happened. It is going to have to be a different configuring of servers. It must be.



--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2006-09-05 10:57:00

That is even odder because I had initially left it off to get the email reports. Even having stuck it back on the end of the crontab line the script still runs but of course I get no emailed result because of the >/dev/null 2>&1.

Here is the crontab line I was using.

MAILTO=username
1,11,21,31,41,51 * * * * /usr/local/bin/php /home/username/test/script.php >/dev/null 2>&1

Still you have your script working. Put it down to DreamHost smile



--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: MAdMoNKEY
Posted on: 2007-01-15 14:21:00

I'm having the same problem--my script runs fine on the command-line, but CRON keeps spitting out "No input file specified" errors. I've tried everything I can think of to no avail. Do you mind posting how you solved this issue? Thanks in advance.

Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2007-01-16 05:35:00

zackwragg mentioned he had left the dev/null off the end and then it worked. Did you try that? Or he may have had a response from the support people.



--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: MAdMoNKEY
Posted on: 2007-01-16 11:33:00

Actually, I didn't have "dev/null" at the end. My crontab entry was:

* * * * * /dh/cgi-system/php.cgi /home/roshangupta/cronjobs.php


My script was a test script that simply sent an email:

#!/usr/local/bin/php -q
<?php
mail('test@atastandstill.com', 'Test subject', 'Test body');
?>


When I manually invoke the script, it runs fine. But when I invoke the script via a cron job, I keep getting "Input file not specified", similar to zackwragg. I've tried every combinatino of using "/usr/local/bin/php" and "/dh/cgi-system/php.cgi" as well as including/excluding the line "#!/usr/local/bin/php -q" from the top of my php script.

Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2007-01-16 13:05:00

Is cronjobs.php in the right location, in the root of your account?


--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2007-01-16 13:19:00

Just set this up as you have it and it works okay.

Make sure that /home/roshangupta/cronjobs.php is exactly where cronjobs.php is and not under your website root.

When you complete the crontab entry using crontab -e make sure you have added a blank line at the end before you save the crontab.

If you still have no success you may have to contact support.


--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: MAdMoNKEY
Posted on: 2007-01-16 13:22:00

You know, it was under /home/roshangupta/atastandstill.com. But the entry I gave you listed it under /home/roshangupta. I think I might have copied "cronjobs.php" to the root directory (as described in my crontab) to try it out in that location, but not sure. I'll give it another shot tonight and let you know if I'm successful. Thanks for the help.

Re: PHP Cron Job Problems

Posted by: MAdMoNKEY
Posted on: 2007-01-16 13:40:00

Ok, I couldn't wait, just tried it. Here is my cron:

temple:~> crontab -l
MAILTO=roshan@atastandstill.com
* * * * * /dh/cgi-system/php.cgi /home/roshangupta/cronjobs.php


Here is my "cronjobs.php":

temple:~> pwd
/home/.heckel/roshangupta
temple:~> more cronjobs.php
#!/usr/local/bin/php -q
<?php
mail('roshan@atastandstill.com', 'Test subject', 'Test body');
?>

temple:~>



I get the following email every minute from root@temple.dreamhost.com:

Status: 404
X-Powered-By: PHP/4.4.4
Content-type: text/html

No input file specified.


When I run "/dh/cgi-system/php.cgi /home/roshangupta/cronjobs.php" in my command line, I get the correct email with subject "Test subject" as expected.


Help!

Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2007-01-16 13:45:00

What permissions do you have for the cronjobs.php file?

Have you tested the cron with the MAILTO line removed?



--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: MAdMoNKEY
Posted on: 2007-01-16 13:50:00

I just tried it with the MAILTO removed, but I never get the email I supposedly should get with my "cronjobs.php" script. I also stopped getting the status emails from root@temple.dreamhost.com like I used to.

Here are the persmission of the two files in my "/home/roshangupta" directory. I don't think cronjobs.cron matters, once it's been loaded into crontab.


-rw-r--r-- 1 roshangupta pg501846 98 2007-01-15 14:11 cronjobs.cron
-rwxr--r-- 1 roshangupta pg501846 97 2007-01-16 13:28 cronjobs.php

Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2007-01-16 13:56:00

Try your cronjobs.php as 664

chmod 664 cronjobs.php



--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: MAdMoNKEY
Posted on: 2007-01-16 14:22:00

No go :(

-rw-rw-r-- 1 roshangupta pg501846 97 2007-01-16 13:28 cronjobs.php

Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2007-01-16 14:34:00

You will probably have to try support then.

What is cronjob.cron for by the way?



--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: MAdMoNKEY
Posted on: 2007-01-16 14:36:00

It just holds my crontab definitions. I run the following to load all my cronjobs:

1) crontab -r (removes all cronjobs)
2) crontab cronjobs.cron (loads by cron job definitions)
3) crontab -l (confirm my jobs are loaded)


I'll open a support ticket. Thanks for trying :)

Re: PHP Cron Job Problems

Posted by: norm1037
Posted on: 2007-01-16 14:41:00

Okay.

If you haven't already have you tried with an empty crontab by using crontab -e and then putting in the required line rather than loading crontab by an external file?

Sorry could not get it going.


--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: PHP Cron Job Problems

Posted by: MAdMoNKEY
Posted on: 2007-01-16 14:53:00

No go :( I filed a support ticket per your suggestion, I'll post to let you know how/if it gets resolved.

Re: PHP Cron Job Problems

Posted by: nicabar
Posted on: 2007-03-29 16:45:00

I'm having same problem, did support team ever solve this issue?

Some google searching turned up a forum that hinted at script rights. Not sure how I fix this, or if it's even the problem.

thx

Tags: cron jobphp cgiscript phpcgi systememailinput fileusrscriptsdomainrunningcommand line