How to use the Cron Manager?

Status
Not open for further replies.

wbaptist

New Member
Prime Account
Messages
24
Reaction score
1
Points
3
I wrote a PHP script that sends me an email. I want to use the cron manager to run this once a week. The trouble is I tried setting it to run on today date and time, but it did not work. When I run the script manually from my public_html directory with my webbrowser it works fine. I am trying to run another copy of the scipt with the cron manager from a folder on my root directory. Would the command I should put in the "Command to run:" box be: /DIRECTORY_NAME/MY_SCRIPT.php ?? Thanks for your help.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
I am used to running shell scripts or perl scripts a cron jobs.

Add the following as the first line in your php script. Do not wrap in it < ? php tags.

Code:
#!/usr/bin/php

Called the shebang line.

That tells the system to run your script via php. It cannot guess just by the .php extension. You also have to change the permissions to 755 so it is executable. Then the command would be "/full/path/to/your/script.php"

or, you can try

"php /path/to/your/script.php" as the command. That way you are specifically telling the system to use php

Remember to adjust your script so it does not output anything. ie, remove the echo and prints.
 
Last edited:

wbaptist

New Member
Prime Account
Messages
24
Reaction score
1
Points
3
Thanks for you answer descalzo.

Code:
#!/usr/bin/php

<?php

$time=getdate(date("U"));

$to = "*******@*****************.***";
$subject = "Email Tester";
$message = "Mail Sent at: $time[hours]:$time[minutes] and $time[seconds] seconds on $time[weekday], $time[month] $time[mday], $time[year]";
$from = "*******@*****************.***";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
$date=getdate();

?>


This is the code I am using. I set its permissions to 755, but it still does not work. :dunno: It works just fine when I run it directly through the browser from my public_html DIR. Any other ideas?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Then remove the "#!/usr/bin/php" and use "php /path/to/your/script.php" as the command. I know that works (tried it myself).
 

wbaptist

New Member
Prime Account
Messages
24
Reaction score
1
Points
3
Hmm, it still seems to not be working. I figured it was something I was doing wrong, but maybe it is something about the way x10 has my account configured? I'll put in a support ticket and see if they can help me any.
 

zapzack

New Member
Messages
606
Reaction score
19
Points
0
try

Code:
php -q /home/USER/PATH/TO/FILE.php

Edit: make sure you specify an email in the cron job area.. That way, if there's an error, it will email you it.. If it runs successfully, then there is an error in your script..
 
Last edited:

wbaptist

New Member
Prime Account
Messages
24
Reaction score
1
Points
3
Using that switch and pointing it to /home/USER/ before the file path worked. Thanks for the help.

What does that -q switch tell the server to do?
 
Status
Not open for further replies.
Top