PHP Cron Job Problems

software development

#1

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?


#2

What happens if you run it from the web?

–rlparker


#3

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!! :@

You act on my advice at your own risk!


#4

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.


#5

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!! :@

You act on my advice at your own risk!


#6

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


#7

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!! :@

You act on my advice at your own risk!


#8

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.


#9

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!! :@

You act on my advice at your own risk!


#10

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

Thanks for all the help btw. Very much appreciated.


#11

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( '

Database back-up completd successfully

' ); ?>

Any ideas on that one?


#12

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

And is the path for db_dumps okay?

Naaah forget the dot thing :slight_smile:


Norm

Opinions are my own views, not DreamHosts’.
I am NOT a DreamHost employee OK!! :@

You act on my advice at your own risk!


#13

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.


#14

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


#15

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

My website


#16

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


#17

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 :slight_smile:

X-Powered-By: PHP/4.4.2

Content-type: text/html

Database back-up completd successfully

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!! :@

You act on my advice at your own risk!


#18

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


#19

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


#20

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!! :@

You act on my advice at your own risk!