|« 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:
Next I created a shell script in /usr/libexec called dvdinsert
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.
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.
One really shouldn’t echo stuff straight into /var/log/messages; use logger(1) to talk to syslogd and get your messages properly timestamped and all.
Some means of dealing with volume ID collisions could be fun too, especially as they might be the same disk again, might be a second copy of the same volume (with errors in different places, maybe), or might be a different one entirely.
The reason for echoing to /var/log/messages is to aid in script troubleshooting. Of course anyone who find this script useful is encouraged to improve upon it and post the results for others to improve upon.
Thanks for the good howto!
I couldn’t get this to work, but then I found the problem. In debian, /usr/libexec doesn’t exist, so I put my dvdinsert script into /usr/local/bin. But that path is not visible to hal by default.
The solution was to put a symlink in /usr/lib/hal/scripts dir, which points to my dvdinsert script in /usr/local/bin.
Hope this helps someone.
Thank you for the good tutorial.