Kopierstation/Code

Aus Piratenwiki Mirror
Zur Navigation springen Zur Suche springen
#!/bin/sh

DISK1=/tmp/disk1
DISK2=/tmp/disk2

subdir=files_from_other_disk
TEMP=/tmp/$$

DISK1_DIR="$TEMP/disk1"
DISK2_DIR="$TEMP/disk2"

for disk in $DISK1 $DISK2 $TEMP
do
       mkdir -p "$disk"/"$subdir"
       if [ $? -ne 0 ] ; then
               echo could not create directory \"$subdir\"
               exit
       fi
done


cd "$DISK1"
find . -type f -exec md5sum {} \; >> "$DISK1_DIR"
cd "$DISK2"
find . -type f -exec md5sum {} \; >> "$DISK2_DIR"

cd "$DISK1"
cat "$DISK1_DIR" | while read hash filename
do
       if [ `grep -c $hash "$DISK2_DIR"` -eq 0 ]  ; then
               target="$DISK2"/"$subdir"/`dirname "$filename"`
               if [ ! -d  "$target" ] ; then
                       mkdir -p "$target"
               fi
               cp "$filename" "$target"
       fi
done

cd "$DISK2"
cat "$DISK2_DIR" | while read hash filename
do
       if [ `grep -c $hash "$DISK1_DIR"` -eq 0 ]  ; then
               target="$DISK1"/"$subdir"/`dirname "$filename"`
               if [ ! -d  "$target" ] ; then
                       mkdir -p "$target"
               fi
               cp "$filename" "$target"
       fi
done

rm -fr $TEMP

Verbesserungsmöglichkeiten: Verwendung der Hardwarepfade /dev/disk/by-id/usb-blubb oder by-path/blubb und du kannst jeden USB-Hub einzeln ansprechen.