| « Bug bitten ankle day 2, the horror continues | Climate change bites back? » |
Now that hard drives are so cheap I decided to copy a whole stack of archival DVD's onto a hard drive. I wanted to use a shell script because the copy was running on a machine that didn't have a monitor or keyboard attached. The idea was to feed it DVD's every time the drawer popped open until the stack was done.
Step 1 was to add a HAL callout to run a script whenever the DVD was inserted. I create a file called 31-dvdinsert.fdi in /usr/share/hal/fdi/information/20thirdparty/ which is where these things go in Centos or Redhat 5 systems. The name isn't that important but the extension .fdi is. Forget the .fdi and it won't work. On this particular system the DVD drive resides at /dev/hdc, using ls -l /dev/cdrom will show you where it is on your system. The contents of the file were:
XML:
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<deviceinfo version="0.2"> | |
<device> | |
<match key="block.device" string="/dev/hdc"> | |
<append key="info.callouts.add" type="strlist">dvdinsert</append> | |
</match> | |
</device> | |
</deviceinfo> |
Next I created a shell script in /usr/libexec called dvdinsert
Code:
#!/bin/sh | |
echo $HALD_ACTION >> /var/log/messages | |
case $HALD_ACTION in | |
add) | |
sleep 1 # May be unnecessary, experiment | |
echo dvdinsert DVD inserted >> /var/log/messages | |
/usr/libexec/dvdinsert1 "$HAL_PROP_VOLUME_LABEL" & | |
sleep 1 | |
;; | |
remove) | |
echo DVD removed >> /var/log/messages | |
;; | |
esac |
The purpose of this script is to call another script to do the actual copying. HAL callouts can only run for a very short time before they are terminated. This script passes the Volume name of the DVD inserted to dvdinsert1 which is run as a detached process. THe contents of dvdinsert1 are shown below.
Code:
#!/bin/sh | |
echo dvdinsert1 DVD inserted >> /var/log/messages | |
echo $1 >> /var/log/messages | |
mount /dev/hdc /media/dvd | |
echo "mount complete" >> /var/log/messages | |
cp -a /media/dvd "/mnt/backup/$1" | |
echo "copy complete" >> /var/log/messages | |
sleep 1 | |
umount /media/dvd | |
echo "umount complete" >> /var/log/messages | |
/usr/bin/eject | |
echo "eject complete" >> /var/log/messages |
This script does the actual copying of the files to a subdirectory found that it creates in /mnt/backup where an external usb drive is mounted. It also puts some messages in /var/log/messages so that you can keep track of the copy progress. You will need to create the /media/dvd mountpoint so the DVD can be mounted by the script. If you know a better way to do this feel free to leave a comment.