Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4060

Troubleshooting • Udev rule not executed when USB-drive inserted

$
0
0
HI,

I want to activate a script when any (random) USB-drive is inserted in my Raspberry Pi with OS Bullseye. I made a udev-rule (/etc/udev/rules.d/99-usb-autorun.rules) with the folowing content:

Code:

ACTION=="add",KERNEL="sd?1",RUN+="/bin/bash /home/pi/Scripts/usb_handler.sh"
I created a file "usb_handler.sh" in the folder /home/pi/Scripts/ and made it executable with the following command:
sudo chmod +x /home/pi/Scripts/usb_handler.sh

The code in the usb_handler.sh file is:

Code:

#!/bin/bash# Path to LOGfilelog_file="/tmp/usb_handler.log"# Message to writemessage="Script usb_handler.sh is executed on $(date '+%Y-%m-%d %H:%M:%S')"# Write message to logfileecho "$message" >> "$log_file"
I created a second file "usb_handler.log" in the folder /tmp with read and write access for everyone

After reload the udev-rules with the command udevadm control --reload-rules && udevadm trigger or even after a complete reboot, the code is not executed. When I look into the syslog, I see the folowing line:
May 15 18:54:17 raspberrypi systemd-udevd[6306]: sda1: Process '/bin/bash /home/pi/Scripts/usb_handler.sh' failed with exit code 1.

What did I do wrong, and how can I solve this problem?

Statistics: Posted by BramWerbrouck — Thu May 16, 2024 5:47 am



Viewing all articles
Browse latest Browse all 4060

Trending Articles