Here's a little shell script to create backups from many removable discs in a row. The only user interaction in the loop is to change the disc and close the tray. The script waits each time until a new disc is inserted. Thanks to http://serverfault.com/questions/215915/wait-for-tray-closed-or-blank-cd-inserted-in-bash-script for the key snippet of code that waits for the tray!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #!/bin/sh
# Usage: backuploop.sh <input device> <output location>
# No safety checks etc. to keep it compact
# Outer endless loop
while true ; do
echo "waiting for media..."
# This bit loops while the device contains no media
# Sanity checks etc. are left as an exercise to the reader :-P
while udisks --show-info $1 | grep -qc "has media: *0" ; do
sleep 1
done
# This waiting time is necessary to let the device settle
sleep 1
# Here goes your backup operation.
dvdbackup -i $1 -M -p -r a -o $2
# This is important so that the inner loop actually waits.
eject $1
# The status of udisks is update with a short delay after eject returns,
#so we wait a moment.
sleep 5
done
|
Have fun!
Comments
Comments are closed.