I'm working with Raspberry Pi. Previously, I used udev rule to run a script when a usb flash memory was plugged. The following was the content of /etc/udev/rules.d/10-usbstick.rules file:ACTION==add, SUBSYSTEM==block, KERNEL==sd[a-z]1 SYMLINK+=usbflash, RUN+=/path/to/myhup.shAnd then in myhup.sh :#!/bin/shnohup /path/to/myscript.shThis method worked fine. When a usb flash memory was plugged, it automatically started to run the myscript.sh file.However, after upgrading to Jessie, it doesn't work. When plugging a usb flash memory, it gives the following errors:[ 2026.652130] sd 0:0:0:0: [sda] No Caching mode page found[ 2026.652238] sd 0:0:0:0: [sda] Assuming drive cache: write through[ 2029.532163] ntfs: (device sda1): check_mft_mirror(): $MFT and $MFTMirr (record 0) do not match.  Run ntfsfix or chkdsk.[ 2029.532355] ntfs: (device sda1): load_system_files(): $MFTMirr does not match $MFT.  Mounting read-only.  Run ntfsfix and/or chkdsk.I decided to use systemd service method. So I changed the udev rule to:ACTION==add, SUBSYSTEM==block, KERNEL==sd[a-z]1 SYMLINK+=usbflash, RUN+=systemctl start myusb.serviceAnd created the myusb.service with the following content:[Unit]Description=run myscript[Service]Type=oneshotExecStart=/path/to/myscript.sh[Install]WantedBy=multi-user.targetAnd then:sudo chmod 644 /lib/systemd/system/myusb.servicesudo systemctl daemon-reloadsudo systemctl enable myusb.servicesudo rebootThis time, it didn't work again, and gave the following errors:[ 2026.652130] sd 0:0:0:0: [sda] No Caching mode page found[ 2026.652238] sd 0:0:0:0: [sda] Assuming drive cache: write throughSo, how can I run a script automatically when a usb flash memory is plugged (in Jessie)?
How to run a script (when usb memory is plugged) automatically in Debian Jessie (Raspberry Pi)?
debian;usb;systemd;raspberry pi;udev