Author: Stephen Davies Date: To: hampshire Subject: [Hampshire] Re: Handling Volume Labels with Spaces
Thanks for the suggestions. I have got the script working now on my
Laptop. I'll tweak it for the EeePc on Wednesday evening
For anyone who might have the slightest interest, here it the script as
it currently stands. I know there are alternative ways to do some bits
of this but the end user is not really a Linux Person so I'm trying to
keep it simple.
----------------------
#!/bin/bash
#
# Compact Flash Card Copy Script
# Prepared for Simon at Aldershot & Farnham Camera Club by Stephen Davies
#
# This script will copy the contents of a Compact Flash Card to TWO
# other devices.
# As the devices are possibly mounted with spaces in their names, we
need to
# get the volume labels properly.
#
# The target copy directory will include the date/time that the copy was
done.
#
input_device=/dev/sdc1
output_dev1=/dev/sdb1
output_dev2=/dev/sdd1
#
copy_date=`date +"%Y-%b-%d_%H_%M_%S"`
copy_datZ=`date +"%Y-%b-%d"`
copy_time=`date +"%H:%M:%S"`
printf "\n CF Card Copy Script Started at %s %s\n" $copy_datZ $copy_time
#
input_volume=`cat /proc/mounts | grep $input_device | awk '{ print $2 }' | sed -e 's#\\040# #'` output_vol1=`cat /proc/mounts | grep $output_dev1 | awk '{ print $2 }' |
sed -e 's#\\040# #'`
output_vol2=`cat /proc/mounts | grep $output_dev2 | awk '{ print $2 }' |
sed -e 's#\\040# #'`
#
# copy the cards
#
printf "\n - Creating Target directories\n"
printf " %s\%s" $output_vol1 $copy_date
mkdir ${output_vol1}/${copy_date}
printf " ... Done\n"
printf " %s\%s" $output_vol2 $copy_date
mkdir ${output_vol2}/${copy_date}
printf " ... Done\n - Copying Data\n %s\%s" $output_vol1 $copy_date
#
cd $input_volume
cp -R . ${output_vol1}/${copy_date}/.
printf " .. Done\n"
printf " %s\%s" $output_vol2 $copy_date
cp -R . ${output_vol2}/${copy_date}/.
printf " ... Done\n"
#
# finally, get the size of the data we have sourced and copied
#
invol_size=`du -k . | tail -1 | awk '{print $1 }'`
outvol1_size=`du -k ${output_vol1}/${copy_date}/. | tail -1 | awk
'{print $1 }'`
outvol2_size=`du -k ${output_vol2}/${copy_date}/. | tail -1 | awk
'{print $1 }'`
printf "\n Source Volume Data Size = %s\n" $invol_size
printf " Output Volume 1 Data Copied = %s\n" $outvol1_size
printf " Output Volume 2 Data Copied = %s\n\n" $outvol2_size
#
# All Done.
#
end_time=`date +"%H:%M:%S"`
printf "\n CF Card Copy Script Completed at %s %s\n" $copy_datZ $end_time
----------------------
A typical output that you get is as follows:-
----------------------
[sdavi@tiger750 simon]$ ./cf_copy
CF Card Copy Script Started at 2008-Feb-15 16:03:57