Your script must be executable.
Do this step by step to find out your problem:
First create a simple script:
sudo nano /bin/device_added.sh
Add the following lines in the device_added.sh
script
#!/bin/bash
echo "USB device added at $(date)" >>/tmp/scripts.log
Open the second script.
sudo nano /bin/device_removed.sh
Then add the following lines to device_removed.sh
script.
#!/bin/bash
echo "USB device removed at $(date)" >>/tmp/scripts.log
Save the files, close and make both scripts executable.
$ sudo chmod +x /bin/device_added.sh
$ sudo chmod +x /bin/device_removed.sh
Next, let’s create a rule to trigger execution of the above scripts, called /etc/udev/rules.d/80-test.rules
nano /etc/udev/rules.d/80-test.rules
Add these two following rules in it.
SUBSYSTEM=="usb", ACTION=="add", ENV{DEVTYPE}=="usb_device", RUN+="/bin/device_added.sh"
SUBSYSTEM=="usb", ACTION=="remove", ENV{DEVTYPE}=="usb_device", RUN+="/bin/device_removed.sh"
Save the file and close it. Then as root, tell systemd-udevd to reload the rules files (this also reloads other databases such as the kernel module index), by running.
sudo udevadm control --reload
Now connect your iphone or any other usb drive into your machine and check if the device_added.sh
script was executed. First of all the file scripts.log
should be created under /tmp
.
Then the file should have an entry such as “USB device removed at date_time”
If this steps worked correctly the you can replace the /bin/device_added.sh
script with your script. and place your rule in /etc/udev/rules.d/80-test.rules
udev-for-device-detection-management-in-linux
usbmuxd
installed on your system? If yes then there is probably another udev rule for iPhones on your system which might override your udev rule. – yesno Sep 28 '19 at 15:04