HELP! Cron job on php script HELP!

belservice

Verified User
Joined
Aug 4, 2004
Messages
13
HELP can somebody tell me how to set a cron job? i have a banner rotator script that needs to run a php script each hour using a cron job. I already have tried all ways provided here at direct admin forum but still the cron job do not work.

I need to run a php script every hour using cron job. Can somebody tell me how to do this exactly?? Wich command do i need to use? It's important.

Thanks.
 
Are you trying to setup the cron in the /etc/crontab file or throught directadmin?

Either way set it the location of the script that you want to execute.
This would be to run every hour on the hour:

* */1 * * *
 
It do not work

This way i get an error. I try to insert a cron job with direct admin i get this error doing it the way you saiud

Details


The times must formatted like one of the following (eg. hour, no spaces):
*
1
1-5
0-23/2
1,2,3,13,22
0-4,8-12

Look above the error i get.
 
That's always there ;) No error! :)

2 Options to fix and set a script to correctly execute:

Option 1:

Add #![path to php executable]/php on first line. Set it executable and ADD it!

Option 2 (less fuzzz):

use the following command: /[path to php executable/php /[location of your php file]/banner_rotate.php

It should work correctly then ;) Almost everyone makes one of these mistakes ;)
 
Really it will not work

Thank you for you're fast reply sir, but still sir i do not understand how to set a cron job to execute a php script. I am using php adsnews. THis is a banner manager. It need to run a cron job each hour. But really it will not work the way you tell me sir? can you pls tell me exactly how to set the script to run? what are the exact steps to take?

And are they other ways to set a cron job? for free? Because i think that with direct admin it will not work, i tried all ways yet. What really is dissaointing. If you read the direct admin product page they say cron jobs are a piece of cake, but really is'nt.

Thanks.
 
Acutally setting cron jobs is very easy in Directadmin. If you are not familar with what a cron job is, then I can understand why you would think it is hard.

If you want it to run once an hour you need to leave every time field as an asterisk, exept the minutes. There you would put the number of minutes past the hour you want to job to run. For example if you want it to run every hour on the hour, you would put the number 0 there.

The 'Command' field should contain the runtime and the script. So to run something called test.php in a cron job it might look like this:
Code:
/usr/local/bin/php /home/myname/test.php
Where myname is the domain owner name, and this assumes that test.php exists in that directory.

That is pretty much all you need to do to get it to work. If it fails then you might be having other problems like a required file is not found. You have to assume that when a cron job runs, it has no $PATH set and has no relative path, so always us a full path.
 
PLSs still need help

Thanks you all for you're reply on this but still my cron job will not work. I am using phpads new. This script needs to run a cron job each hour for the maintainance. Really i tried all ways you explain but still the cron job will not work. I hope that there is somebody there that can explain to me as a dummy how to set the cron job? I will appriciate it.

Somebody knows if da has a bug with cron jobs? Because all the ways they explain it to me it will not work.

THANKS
 
Check the /etc/crontab file and look if it has a valid email adres in it to send errors to! It will send problems and output to the email adres.

Normaly root ;)

EDIT /etc/crontab:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=your email adres
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
 
Last edited:
Perhaps instead of just saying it does not work, you should tell us exactly what is happening. Are you getting an error message and if so what does it say. I run a php cron job and it works just fine, so I don't thing DA is the problem. All we can do with what you have given us is guess.

My guess is that it is an environment problem.
 
Thanks

Thanks for you're fast reply. I never get an error when i create a cron job, I also do not see the file folder /etc/crontab.
 
Thanks

Thanks again for the fast reply. I see that you are comming from the Netherlands. Do you speak Dutch? fusionictnl?

I also do not see a folder called ssh. The only error i get when i create a cron job is that i get a message about run time error. When i go back to the cron job section the cron job is created, as far as i can see but it do not run the script like it should be. I never get e-mal messages about errors.
 
Re: Thanks

belservice said:

I also do not see a folder called ssh. The only error i get when i create a cron job is that i get a message about run time error. When i go back to the cron job section the cron job is created, as far as i can see but it do not run the script like it should be. I never get e-mal messages about errors.
What he meant, was to log in to the server with ssh. It is similar to telnet but much more secure. Do you have ssh access to your server?

What does the run time error say, this could be important. Cron jobs always send the output, if any to the owners email address. That address for DA would be the [email protected] where username is the username you use to login to the DA control panel with . The only time you won't get an email is if the execution produced no output to stdout or stderr. Have you read the email for the domainowner?
 
Back
Top