Skip to content

Instantly share code, notes, and snippets.

@stanwu
Created July 24, 2012 13:31
Show Gist options
  • Save stanwu/3169931 to your computer and use it in GitHub Desktop.
Save stanwu/3169931 to your computer and use it in GitHub Desktop.
archive files to target folder
#!/bin/sh
#
# This shell script is design for Synology DS-411
# auto move all of the archived files to /volume1/archives folder
#
b=`basename "$1"`
d=`pwd`
echo "[RUN] Check [$b] $d/$1"
if [ -f "$1" ]; then
if [ -e "/volume1/archives/$b" ]; then
echo "[ERR] $1 move to /volume1/archives/$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}'`
fi
if [ -s "/volume1/archives/$b.md5" ]; then
t=`cat "/volume1/archives/$b.md5" | awk '{print $1}'`
else
t=`md5sum "/volume1/archives/$b" | awk '{print $1}'`
fi
if [ "$s" == "$t" ]; then
echo "[DEL] Remove duplicate file"
if [ "$2" == "true" ]; then
rm -f "$1"
[ $? == 0 ] && echo "$d/$1" >> "/volume1/archives/$b.txt"
fi
else
echo $s
echo $t
fi
echo "$s $b" > "$1.md5"
else
echo "[OK] Move $1 to /volume1/archives/"
if [ "$2" == "true" ]; then
mv "$1" /volume1/archives/
if [ $? == 0 ]; then
echo "$d/$1" > "/volume1/archives/$b.txt"
echo "The file $b have move to /volume1/archives" > "$1.txt"
fi
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment