Adding an OSMC menu entry to run an arbitrary bash script

As long as you’re using systemd-based fstab mounts, I’d have thought a systemd service “unit” would do the trick (though you’ll probably need one unit file per disk).

In the /etc/fstab you’d need to associate the disk’s UUID with its mount point. See here.

Then for each mount point, create a .service file in /etc/systemd/system. I think the name can be arbitrary but it’s better to associate it with the mount point name, so I’ve called this one mnt-test.service since it’s for a mount point of /mnt/test.

osmc@osmc:~$ cat /etc/systemd/system/mnt-test.service 
[Unit]
Description=Run script when /mnt/test is mounted
Requires=mnt-test.mount
After=mnt-test.mount

[Service]
ExecStart=/home/osmc/logit.sh
Type=forking

[Install]
WantedBy=mnt-test.mount

My script logit.sh just writes a message to the system journal, BTW.

Remember to enable it (sudo systemctl enable mnt-test.sh).

I can’t guarantee that it’ll work first time but it should be a step in the right direction. One caveat: if you’re using autofs, then this isn’t going to work.