I'm trying to make it so that when I insert a dvd into the cdrom It exports it into an iso using dd. Here's the script for exporting to an iso
#!/bin/bash
timestamp=$(date +"%Y%m%d_%H%M%S")
filename="/home/tom/sambashare/${timestamp}.iso"
dd if=/dev/sr0 of=${filename} status=progress
md5sum ${filename} > ${filename}.md5
The script works just fine when launched from the terminal. Hovewer when I try to launch it from udev (using an udev rule) it will create a file and add some kind of data to it till about 139mb where it stops and gets stuck. An interesting thing is that the computer doesn't make any noises like it does when it's reading the dvd when launched from terminal
Here is the udev rule:
ACTION=="change", KERNEL=="sr0", SUBSYSTEM=="block", ENV{ID_CDROM_MEDIA}=="1", RUN+="/home/tom/mybashscript.sh"
I tried adding a sudo into the udev rule which didn't work as well. Using cat instead of dd shows the same behaviour.
dd
instead ofcat
? Does it work as expected if you usecat
instead? (I doubt it, to be honest, butdd
is weird) – terdon Mar 12 '24 at 16:53udev.script -> script1 -> script2 &
? – terdon Mar 12 '24 at 17:11udev.script -> script1 &
can be good enough? – Rinzwind Mar 12 '24 at 18:14sr0
isn't made available to your script until that rule finishes evaluation and completes execution which is not going to happen given your script operates on that same device ... Please, see for example Different behaviour of bash script in udev ... Also, "somewhat" related https://askubuntu.com/q/1503723/968501 on taggingsystemd
instead and use a systemd system service. – Raffa Mar 12 '24 at 18:16DirectoryNotEmpty=/media/your-username/
that triggers another systemd unit that starts your script. I made something similiar for backup my $HOME when my backup harddrive connects. – nobody Mar 14 '24 at 16:46