0

Attempting to run a PHP script via shell script and keep getting a 'syntax error' from Monit when reading the shell script.

launchQueue.sh

#!/bin/sh
php /var/app/current/hello.php

The shell script will run on it's own and I've opened up all permissions. Monit is calling it from it's own directory /etc/monit.d/* - which is supposed to run all files within it when monit starts up.

Exact error reads: "/etc/monit.d/launchQueue.sh:2: Error: syntax error 'php'"

  • I have moved it out of monit.d as this post suggests, but I get the same error.

Running Monit Versions 5.2.5

MortiestMorty
  • 635
  • 1
  • 5
  • 13
  • You're missing the `!` in `#!/bin/sh`, for starters. – larsks Oct 26 '17 at 19:24
  • I had "!" in there, it was a type when inserting it on stack. – MortiestMorty Oct 26 '17 at 19:50
  • Your error refers to `launchQueue.sh`, but your example shows `launchHello.sh`. Are the contents you're showing here identical to the file that is causing this error? Are you certain there's not a hidden carriage return (`\r`) at the end of the previous line (you can check with `od -a ` and look for "cr" in the output)? – larsks Oct 26 '17 at 19:54
  • Also, take a look at https://stackoverflow.com/questions/17101842/monit-errors-when-running-check-program-for-custom-script – larsks Oct 26 '17 at 19:55
  • Ya, sorry. launchQueue = launchHello - It's been a long day. This has taken up the majority of it... That stack question you mention was the one I was referring to when I said, i had already taken the sh script out of monit.d. – MortiestMorty Oct 26 '17 at 20:01
  • Oops, sorry. Hadn't followed that link yet. – larsks Oct 26 '17 at 20:05
  • No worries, I'm going with SupervisorD instead of Monit. Monit just isn't working for me. – MortiestMorty Oct 26 '17 at 20:48

2 Answers2

1

Monit is having it own PATH and it is very small PATH. You should provide the full path to you php executable or re-defined the PATH in your script.

Try with (tune according to your location)

#!/bin/sh /usr/bin/php /var/app/current/hello.php

TheCodeKiller
  • 1,733
  • 2
  • 12
  • 18
0

I figured out what the issue was and it was largely due to my own ignorance of using the terminal (I'm pretty new). I installed SupervisorD and ran into similar issues. It turned out that my root $PATH didn't include the normal user (?) $PATH. Once I exported the PATH over to root, it ran just fine.

MortiestMorty
  • 635
  • 1
  • 5
  • 13