I would like to setup a Raspberry Pi 3 running Rasbian to automatically copy a DVD disk when a disk is inserted in a coupled disk station. To achieve this, I have written a udevrule and a script to run when this rule is triggered.
The udev rule seems to work fine and runs the script when the disk is inserted.
The script contains the dd
command. When i execute the script manually from the command line, it works correctly and executes the dd
command. When the script is run by udev
on disk insertion however, everthing in the script executes, except the dd
command.
I have searched online but could not find anyone else with the same issue. Does someone have a clue what the problem might be?
udev rule /etc/udev/rules.d/65-autorip.rules
:
SUBSYSTEM=="block", KERNEL=="sr[0-4]", ACTION=="change", RUN+="/usr/local/bin/autorip/autorip.sh /dev/%k %E{ID_CDROM_MEDIA}"
disk copy script /usr/local/bin/autorip/autorip.sh
:
#!/bin/bash
# function to activate a led and eject disk when an error occurs
error(){
python /usr/local/bin/autorip/led-on.py
eject
}
# function to deactivate the led for
reset_led(){
python /usr/local/bin/autorip/led-off.py
}
# if udev flag to check if disk change action is insert (second script parameter) is set
if [ $2 == "1" ]; then
reset_led
#use wodim command to find out if disk is DVD
disk_info=$(wodim -atip dev='/dev/sr0')
if [[ $disk_info = *"mmc_mdvd"* ]] ; then
# copy disk contents to temp location (not working when ran from udev)
dd if=/dev/sr0 of=/tmp/autorip_disk_image_$RANDOM$RANDOM.iso
eject
else
error
fi
fi
dd
command to call it? – Rui F Ribeiro Apr 15 '18 at 16:05dd
for this. Just usecat
. – terdon Apr 15 '18 at 16:22