Jump to content

Recommended Posts

Posted

Hello,

 

I am trying to execute a .php file using cronjobs but it seems I am experiencing some trouble with the syntax I use.

 

I have set up in cpanel a cronjob with the following command to be executed:

/home1/<myaccountname>/public_html/<myphpfile>.php

 

And I have created the following simple .php file (see the code below):

#!/usr/local/bin/php

<?php

echo date("F j, Y, g:i a");

?>

 

The problem is that I cannot get to execute it, as I receive the following error:

/bin/sh: /home1/<myaccountname>/public_html/<myphpfile>.php: /usr/local/bin/php: bad interpreter: No such file or directory

I would go on and try a couple of different options but I run out of permitted cronjob executions.

 

Could you please help me set up properly the cronjob??

 

Thnks.

Posted

Should be:

 

php -q /home1/<myaccountname>/public_html/<myphpfile>.php

 

If you don't wish to receive an email each time cron runs, then:

 

php -q /home1/<myaccountname>/public_html/<myphpfile>.php >/dev/null 2>&1

 

 

Also you don't need this line for php files:

 

#!/usr/local/bin/php

 

Just use php tags for any php code:

 

<?php
echo date("F j, Y, g:i a");
?>

Posted

OK, thanks for the input. It finally worked but with a small update in your code (replacement of option '-p' with option '-q'):

 

php -q /home1/<myaccountname>/public_html/<myphpfile>.php

 

p.s: how can I mark this topic as [sOLVED]?

Posted

Admins usually mark threads as solved, though we usually just stick [sOLVED] at the start of the topic title. :lol:

I'll go ahead and mark this solved:

 

Glad your problem got solved! :D

 

Please spare a few minutes to take our brief survey:

http://feedback.heliohost.org/

Your participation in this survey is greatly appreciated.

Posted
OK, thanks for the input. It finally worked but with a small update in your code (replacement of option '-p' with option '-q'):

 

Oops, sorry for my typo. I hope it didn't cause you too many headaches! :( I'll edit my post to show it corrected.

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...