vendredi 4 février 2011

How to automout, autocopy and autoeject discs

Tested in Ubuntu 10.10.

sudo apt-get install ddrescue

create a file named 'autocopy' with following content:

#!/bin/bash

CDDEV="/dev/sr0"
TARGET_DIR="/saved"

IFS=$'\n'

while [ 1 ]
do
input="$(cat /etc/mtab | grep $CDDEV | awk 'END { print $2 }' | sed 's/\\040/ /g')"
if [ -d "$input" ]
then
cd $input
for file in *
do
if [ -d $file ]
then
cd $file
for file in *
do
echo copying: $file
time ddrescue $file $TARGET_DIR/$file
done
cd ..
else
echo copying: $file
time ddrescue $file $TARGET_DIR/$file
fi
done
cd ..
umount -l $CDDEV
while ! eject $CDDEV
do
sleep 1
done
fi
sleep 1
done

Adjust CDDEV and TARGET_DIR.

chmod +x autocopy

sudo ./autocopy

This will save any inserted disc (only * and */* files) to the specified location.
The copy is performed by ddrescue, which can recover damaged discs.

Aucun commentaire:

Enregistrer un commentaire