Little help with simple Cron Job


#1

Hi, I was looking for a little help with a simple cron job that will just run a simple php page every hour.

I took a look through this forum and found some discussions but was unable to use the solutions mentioned.

I have gotten a cron to do this on a different hosting successully. I had a quick livechat with someone from dreamhost and they thought this may do it:

php -q -f /home/user/url/cron/cron.php

It won’t work and I get no email if I enter it. I have 2 users, both with webshell access and “enhanced security”. I have been selecting the user from the dropdown that matches the user in the script above. I have tried about 7 or 8 different scripts I have read on various forums with no luck.

This should be about the easiest thing a cron can do but it has me stumped. Any help would be greatly appreciated. Thanks.


#2

I assume that you have tried to run this manually by simply pointing your browser to http://url/cron/cron.php What happens with that test? And is the email you are expecting only the cron generated email? or does the script itself send mail using mail(). The reason I ask these questions is that sometimes a dreamhost webserver has issues sending email… i.e. they have been RBL’d as mail senders. So one question to sort out is it’s really working for you but the email is getting blocked.

Second, using php -q -f /home/user/url/cron/cron.php is probably going to get php 5.2 I would use

/usr/local/php53/bin/php /home//path/to/script.php

More examples: http://wiki.dreamhost.com/Run_PHP_from_cron

And third, if your script is generating the email using mail() then make 100% certain that the email is being sent FROM a valid email address at your domain. You can’t spoof the FROM address at dreamhost, and many ready made scripts (especially contact form variety scripts) attempt to do that.


#3

LakeRat, thanks for your reply.

The email I was referring to is the email form the cron job itself that sends to the email you enter when setting it up.

The page, when run manually by visiting it in a browser, works as it should, but I can’t get the Cron to trigger it.

I believe I already tried the longer version of php, but I will try again and let you know.


#4

If the email address you are specifying is outside dreamhost, try one at dreamhost. again the reason is dreamhost webservers can be RBL’d to the outside world.


#5

LakeRat, I will try a dreamhost email for the output.

This: /usr/local/php53/bin/php /home//path/to/script.php

Still does not work. Any other suggestions?


#6

What’s your webservers name? And whAt domain (the part after the @) was the email address you were using?


#7

gregmisener.net

The email I have entered in the cron is now @gregmisener.net

Since changing the email it now sends an output message “Could not open input file: /home/gmisener/gregmisener.net/xxx/xxx/xxxx.php”

xxxxs are there to hide the full url which is irrelevant.

You got me a little further with the email help. Any ideas why that url can not be found? Thanks again.


#8

sounds like you’re not translating your URL correctly.

So you said you can visit the url http://gregmisener.net/xxx/xxx/xxxx.php and the file runs, but for some reason when you try to call it /home/gmisener/gregmisener.net/xxx/xxx/xxxx.php it’s not there. Remember that case counts /path/to/url.php and Path/To/URL.php are two different things.

the actual question i asked before about the webserver meant the name of the server your on (I was going to check it against email RBL’s) but it sounds like we got passed that point.


#9

Yes, that is correct, when i view the http://gregmisener.net/xxx/xxx/xxxx.php in a browser it executes the php fine but /home/gmisener/gregmisener.net/xxx/xxx/xxxx.php does not and I double-checked the case.


#10

things that you can check:
1- file permissions - the php file should be 755 and all the folders above it (back up to gregmisener.net directory) should be 644. Running the file via a browser/apache will use world permissions while when it runs from cron it will run as owner.
2- Navigate to manage domains in the panel, and find the line for gregmisener.net – look at the webhosting column, is the user listed there gmisener? is that the user you are using on the first dropdown of the cron page in the panel?


#11

LakeRat, the problem was the usernames. Turns out there were 2 usernames and I should have been using a different one. I used gmisener because it was the login for cpanel but it wasn’t the right one for crons.

All working now. I appreciate your help. Thanks.