Todd Smith Org

November 28, 2012

Quick Script to help you archive all those IOMega ZIP Disks

Filed under: Uncategorized — admin @ 3:13 am
base_file="Zip100_"
base_dir="/Users/smith/Documents/GraphicDesign"


while true ; do

    if [ -d "/Volumes/Zip 100" ] ; then
        vol_dir="/Volumes/Zip 100"
    elif [ -d "/Volumes/ZIP-100" ] ; then
        vol_dir="/Volumes/ZIP-100"
    elif [ -d "/Volumes/100zip" ] ; then
        vol_dir="/Volumes/100zip"
    fi

    if [ -d "${vol_dir}" ] ; then

        ls -1 $base_dir
        last=`ls -1 $base_dir/ | cut -f2 -d_ | tail -n1 | sed "s,^[0],,g"`
        echo "Last: ${base_dir}/${base_file}`printf '%02d' ${last}`/"
        if [ -f "${base_dir}/${base_file}`printf '%02d' ${last}`/.done" ] ; then
                #move to next one
                echo "${base_dir}/${base_file}`printf '%02d' ${last}`/ is DONE"
                next=`printf "%02d" $(($last + 1))`
                echo Next is "${base_dir}/${base_file}${next}/"
                mkdir "${base_dir}/${base_file}${next}/" && \
                rsync -av --progress --stats "${vol_dir}/"* "${base_dir}/${base_file}${next}/" && \
                touch "${base_dir}/${base_file}${next}/.done" && \
                hdiutil detach "${vol_dir}"
        else
                #rsync copy to last && \
                rsync -av --progress --stats "${vol_dir}/"* "${base_dir}/${base_file}`printf '%02d' ${last}`/" && \
                touch "${base_dir}/${base_file}`printf '%02d' ${last}`/.done" && \
                hdiutil detach "${vol_dir}"
        fi

        sleep 10

    else

        echo "Volume does not exist, sleeping for 5 seconds"
        sleep 5

    fi

done

Powered by WordPress