0

I have several php scripts I am trying to set up (recently moved to a new server) they will run from the command line and through the browser but only one will run through cron the other seems to have a permissions problem, if the file is set to 644 I get this message from cron: /bin/sh: /home/xyz/public_html/scripts/update-script.php: Permission denied

If I set permissions to 777 I get this message:

/home/xyz/public_html/scripts/update-script.php: line 1: ?php: No such file or directory

/home/xyz/public_html/scripts/update-script.php: line 2: syntax error near unexpected token `"includes/clsDatabase-list.php"'

/home/xyz/public_html/scripts/update-script.php: line 2: ` require_once("includes/clsDatabase-list.php");'

yet the script runs from the command line and via browser AND i have another script that is almost identical to this one (calls for the same include on line 1, is located in exactly same folder) that will run through cron! So I know my paths and cron job that I setup in Cpanel are right. If I copy the working one in the command line, the copied version also fails to run via cron. Thanks!

2
  • show your script code Commented Apr 4, 2014 at 13:35
  • Not really necessary, the error contains all necessary information. Commented Apr 4, 2014 at 13:36

1 Answer 1

1

You need to add a shebang to your file to execute it directly:

#!/usr/bin/env php
<?php
//...

Another option would be calling it like this in your cronjob:

* * * * * php /home/xyz/public_html/scripts/update-script.php

Of course you'd replace the * * * * * with the actual crontab data unless you want it to run every minute.

Sign up to request clarification or add additional context in comments.

1 Comment

Shebang worked! Not sure why one script needs and other doesnt, also your second option is exactly how the script was called and doesnt works. Thank you very much

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.