How to run Python script on USB flash-drive insertion

Viewed 4192

My goal is to run a Python script on USB flash-drive insertion. I have written a udev rule and a shell script that is called in that rule.

udev rule: /etc/udev/rules.d/10-usb.rules

KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="usb", RUN+="/home/Hypotheron/Desktop/script.sh" 

script.sh:

#!/bin/sh

echo 'Hello, world.' > /home/Hypotheron/Desktop/foo.txt
#/home/Hypotheron/Desktop/job.py & exit

The first line of my Python file is:

#!/usr/bin/python 

I also did these following commands:

chmod +x job.py
chmod +x script.sh

In the script.sh when the line writing to foo.txt is uncommented the foo.txt file is created every flash-drive insertion.

When I comment that line and uncomment the line running the Python file it doesn't work.

Running the script.sh through terminal works in both cases but when inserting a flash-drive only the foo.txt case works.

Any help would be appreciated.

1 Answers
Related