1

Trying to use Crontab to execute commands at regular intervals. But crontab keeps giving the error:

/bin/sh: /var/www/html/Scripts/lib/Tasks.php: /usr/bin/php^M: bad interpreter: No such file or directory

Tasks.php:

#!/usr/bin/php
<?php
//scripts
?>

I feel like my Shebang is messed up. The main php file appears to be present in /usr/bin/php but I keep getting the error. I have been trying other shebangs from other posts but most of them are not using the combination of Centos6 php5 and apache. I just need to execute this php script every few min.

t j
  • 7,026
  • 12
  • 46
  • 66
MoonEater916
  • 436
  • 2
  • 6
  • 19
  • 4
    Possible duplicate of [Are shell scripts sensitive to encoding and line endings?](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings) – tripleee Nov 20 '17 at 10:21

1 Answers1

2

In php file shebang operator will not work as per my understanding.

You can rewrite crontab as below:

* * * * * /usr/bin/php /var/www/html/Scripts/lib/Tasks.php

You can change crontab frequency as per you need. Also please verify if php is at right place with below command:

which php

Thanks.

  • This resolved that issue however parse_ini_file(/Config/Config.ini): failed to open stream: No such file or directory in. – MoonEater916 Nov 20 '17 at 04:53
  • Please provide absolute path in parse_ini_file function from root folder or the folder relative to the file in which this code is written – Ramdas Gaikar Nov 20 '17 at 05:10
  • I solved it already i was posting that there for anyone else experiencing issues. Thank you so much Ramdas. – MoonEater916 Nov 20 '17 at 05:24