Hallo!
ich versuche ein Python Script zu starten, wenn ein USB-Stick eingesteckt wird.
Das ganze funktioniert auch zum Teil.
Ich habe die Regel "/etc/udev/rules.d/91-usb-mount.rules" erstellt:
Code
ACTION=="add",ENV{DEVTYPE}=="usb_device",ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/pi/.Xauthority",RUN+="/usr/bin/python /home/pi/python/usb.py rein"
ACTION=="remove",ENV{DEVTYPE}=="usb_device",ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/pi/.Xauthority",RUN+="/usr/bin/python /home/pi/python/usb.py raus"
zum testen sah mein Script so aus:
Python
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
os.system("echo \"$(date) usb stick "+sys.argv[1]+"\" >> /tmp/usbstick.log")
was funktioniert hat.
Nun habe ich folgendes Ergänzt:
Python
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import requests
log_id = "XXX"
chat_id = "XXX"
parse_mode = "HTML"
requests.get("https://api.telegram.org/bot"+log_id+"/sendMessage?chat_id="+chat_id+"&parse_mode="+parse_mode+"&text=+str(sys.argv[1]))
wenn ich das Script einzeln teste funktioniert es. Als Sudo und als Pi. Jedoch automatisch funktioniert es nicht. Im Syslog taucht "systemd-udevd[22762]: 3-1: Process '/usr/bin/python /home/pi/python/usb.py rein' failed with exit code 1."
auf.
Ich vermute dass mein Rule-Eintrag nicht ordentlich ist (habe ich mir ehrlich gesagt auch nur zusammen gegoogelt).
Kann mir jemand weiterhelfen?
Danke schonmal!