I managed to create a Python script to accept magnetic card swipes from a USB-based reader. It seems to work as expected. Part of the routine is a curl command to push the data to another server. Since the Ubuntu server won't have a monitor/keyboard/mouse my only way of responding to the user is with sound from the server's speaker.
Usually, the curl command gets a standard 200 response from the other application server. Sometimes, however, it gets a 500 error response and I need to communicate something back to the user to alert them that "this time didn't work, please scan your card again".
A simple mechanism is to beep once for success and nothing for failure. As written and run from a terminal, it works. As scheduled from rc.local, the system beep doesn't sound.
...
args = 'card=' + trackone.group(2)
r = requests.get('http://apiserver/api/', args)
if r.status_code == 200:
# First attempt which doesn't work from rc.local
# print("\a")
# Second attempt, wrap the beep in a shell script
os.system("sh /home/myuser/beep.sh")
else
print(r.status_code)
And I attempted to create a simple shell script beep.sh:
#!/bin/bash
echo "\a"
As mentioned, both attempts work from the terminal but not as run from root under rc.local control. And I know that the API is being called since I can see the log entries.
The line in rc.local looks like this:
python '/home/myuser/scancards.py'
Is there a way to allow this command--as run within the init.d process--to be able to beep the speaker?