I'm trying to execute a script on a raspberry pi to control a bluetooth device via a url cgi (apache2) script. There may be other ways to do this, but I've struggled to get php installed without bricking the OS (several hours wasted) and I'm not interested in anything complicated.
I have a working bash script that controls the bluetooth device from the raspberry pi. However, when this same script is called via a url (i.e. /cgi-bin/example5.sh) bluetoothctl returns "No default controller available" instead. I can run simple scripts with no problem, but somehow bluetoothctl isn't executing the same way via the url. Is there possibly an ownership or environment variable problem" The script has 755 permissions and owned by root. Any help in debugging would be appreciated.
My script is /usr/lib/cgi-bin/example5.sh and simply calls tries to connect to the bluetooth device via bluetoothctl (real bluetooth device mac address removed because, you know, people).
#!/bin/bash -e
echo Content-type: text/plain
echo
bluetoothctl -- connect "XX:XX:XX:XX:XX:XX"
From the command line this works correctly:
pi@raspberrypi:/usr/lib/cgi-bin $ ./example5.sh
Content-type: text/plain
Attempting to connect to XX:XX:XX:XX:XX:XX
Connection successful
When I enter http://<my local IP address>/cgi-bin/example5.sh I get the following in the webpage.
No default controller available
#!/bin/bash echo ./i.sh 2is that actually what you have in the file/. that's not a valid invocation of bash#!/bin/bashwhen you do this, your script won't end on errors. Use#!/bin/bash -eusually so that your script will "error out" rather than continuing with further commands which will probably also fail