I want my Ubuntu 15.04 x64 server system to execute a script whenever a certain flash drive is inserted. So I created a custom rule file with the following content
The script executed whenever the flash drive is inserted, but I have two problems with it:
1) The script is apparently not executed when the computer is (re-)started with the drive already inserted. Is there any way to execute the script after startup if the flash drive is already connected?
2) The script wants to mount the device, but If I try to mount the device like
mount LABEL=mylabel /some/path
mount UUID=my-uuid /some/path
The source cannot be found. Currently I inserted a
into my script, but this does not seem like a reliable solution. Is there any (failure tolerant) way to wait for the system to be sufficiently initialized?
For testing purposes, the script only contained
#!/bin/sh date >> /tmp/test.log
date >> /tmp/test.log, (in addition to the shebang) and if I rebooted the system while the pen drive was still inserted, no entry was made.
/tmpis not yet mounted read-write at that point. At least on Debian jessie with sysvinit,
/is still mounted read-only and filesystems from
/etc/fstabaren't mounted yet at the time
udevadm trigger --action=addruns. The robust way on systemd would be to add a unit with the right dependencies, I don't know how to do that.