0

I'm controlling my home automation with a Raspberry Pi and webserver. I use this line to turn on my lights (sending an RC signal to wireless power socket).

exec("sudo ./../../../home/pi/wiringPi/examples/lights/action 63 A on");

This is working when the script is ran by a cron job, but when I manually want to execute this command (using a php form and buttons), it does not work. I tried adding $output, $return); and checking $return, and that confirms the exec() function is not executed. However, when I use something like exec("whoami");, the script is executed.

What is it about my command that makes it work only in cron jobs? I had this working once, don't know what happened. Manually sending the command via ssh in the terminal is working normally.

Jim
  • 41
  • 5
  • 1
    The CRON is running as `root` or as the user you are executing the script as? – chris85 Nov 26 '15 at 15:01
  • 1
    You should probably use absolute path, those relative paths can be tricky. – Latheesan Nov 26 '15 at 15:02
  • My cron job is as follows: `* 15-22 * * * php /var/www/html/script.php >> /var/www/html/logbook.log 2>&1` How do I point to the absolute path? (I'm quite new at linux programming) – Jim Nov 26 '15 at 15:14

1 Answers1

1

Fix permissions on this command and run it without sudo (for ubuntu default php user is www-data, for suse wwwrun, ...). Check the path also. I recommend absolute paths.

izupet
  • 1,529
  • 5
  • 20
  • 42
  • The file that should be executed has 755 permissions. However, removing sudo from the command worked! My problem is solved! Can somebody still explain to me what happened here though? – Jim Nov 26 '15 at 15:29