gtvitini Posted July 30, 2011 Posted July 30, 2011 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.
Byron Posted July 30, 2011 Posted July 30, 2011 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"); ?>
gtvitini Posted July 31, 2011 Author Posted July 31, 2011 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]?
jje Posted July 31, 2011 Posted July 31, 2011 Admins usually mark threads as solved, though we usually just stick [sOLVED] at the start of the topic title. I'll go ahead and mark this solved: Glad your problem got solved! Please spare a few minutes to take our brief survey: http://feedback.heliohost.org/ Your participation in this survey is greatly appreciated.
Byron Posted July 31, 2011 Posted July 31, 2011 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now