I have this python script that is intended to run from startup and listen for a buttonpress. If there is a buttonpress (held for 2s) the gpio script should run two bash scripts. The python script runs if it is done with
python /path/to/script/script.py so I know it is working. If I try to run in from startup by a
@reboot /path/to/script/script.py I can see that it is active when running the
top command. However, the button press will not fire the intended bash scripts. I have tried and modify
~/.bashrc and tried to have a bash script in
crontab -e with
sudo python /path/to/script.py. None of them worked. To complicate things further, If I change it to call a command instead, like
killall -9 openvpn for example... then it works.. what am I doing wrong?
The python script looks like the following
from gpiozero import Button from signal import pause import os def runboth(): os.system("/opt/script/script_a.sh") os.system("/opt/script/script_b.sh") runboth_btn = Button(23, hold_time=2) runboth_btn.when_held = runboth pause()
Below is one bash script I try to run with the button press. Its located in
~/opt/script# and has the permissions
-rwxr-xr-x 1 root root 240 Mar 21 11:58 match_email.sh
#!/bin/bash #run match python /opt/tmp_email/email_match.py wait mv /opt/tmp_email/output.csv /opt/emailoutput$(date -d "today"+"%Y%m%d%H%M").csv
If I try to run it with a
subprocess.call looking like
from gpiozero import Button from signal import pause import subprocess def runboth(): subprocess.call(['sh', '/opt/script/script_a.sh'], shell=False) subprocess.call(['sh', '/opt/script/script_b.sh'], shell=False) runboth_btn = Button(17, hold_time=2) runboth_btn.when_held = runboth pause()
But didn´t work either..
Crontab looks like
I have had a look at Run a shell script from a python script when a button is pressed but that didn´t help me.. Any help is much appreciated!