Skip to content

Instantly share code, notes, and snippets.

@stanwu
Created July 27, 2012 04:38
Show Gist options
  • Save stanwu/3186207 to your computer and use it in GitHub Desktop.
Save stanwu/3186207 to your computer and use it in GitHub Desktop.
archive2
#!/bin/bash
my_target="/mnt/nfs/stan/archives"
b=`basename "$1"`
d=`pwd`
echo "[RUN] Check [$b] $d/$1"
if [ -f "$1" ]; then
if [ -e "$my_target/$b" ]; then
echo "[ERR] $1 move to $my_target/$b (exist!)"
if [ -s "$1.md5" ]; then
s=`cat "$1.md5" | awk '{print $1}'`
else
echo "[RUN] Rebuilt $1 md5sum"
s=`md5sum "$1" | awk '{print $1}'`
echo "$s $b" > "$1.md5"
fi
if [ -s "$my_target/$b.md5" ]; then
t=`cat "$my_target/$b.md5" | awk '{print $1}'`
else
echo "[RUN] Rebuilt $my_target/$b md5sum"
t=`md5sum "$my_target/$b" | awk '{print $1}'`
echo "$t $b" > "$my_target/$b.md5"
fi
if [ "$s" == "$t" ]; then
echo "[DEL] Remove duplicate file"
if [ "$2" == "true" ]; then
rm -f "$1"
[ $? == 0 ] && echo "$d/$1" >> "$my_target/$b.txt"
fi
else
echo $s
echo $t
fi
else
echo "[OK] Move $1 to $my_target/"
if [ "$2" == "true" ]; then
mv "$1" $my_target/
[ -f "$1.md5" ] && mv "$1.md5" $my_target/
if [ $? == 0 ]; then
echo "$d/$1" > "$my_target/$b.txt"
echo "The file $b have move to $my_target" > "$1.txt"
fi
fi
fi
fi
stan@ubuntu1204-64:/usr/local/bin$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment