Auto-rar.sh
解壓縮多個分割檔案 (*.part0XX.rar)
#!/bin/bash
echo "-> Started: "`date +%m/%d/%y\ %H:%M\ %Z`
echo "-> As:"`whoami`
i=1
ARCHIVES="$@"
for f in $ARCHIVES; do
PARTCHECK=$(expr "$f" : ".*\([Pp][Aa][Rr][Tt][0-9]\+\.[Rr][Aa][Rr]\)")
RARCHECK=$(expr "$f" : "\(.*\.[Rr][Aa][Rr]\)")
echo "-> Processing($i of $#): $f"
if [ "$PARTCHECK" ] && [ -f $f ]; then
echo "-> Extracting Multipart Archive"
unrar x $f
if [ $? -eq 0 ]; then
FILES=$(expr "$f" : "\(.*[Pp][Aa][Rr][Tt]\).*")
echo "-> Extraction Successful"
echo "-> Removing $FILES*.rar"
rm $FILES*.rar
else
echo "-> **Extraction Failed"
exit 1
fi
else
if [ "$RARCHECK" ] && [ -f $f ]; then
echo "-> Extracting Single Archive"
unrar x $f
if [ $? -eq 0 ]; then
echo "-> Extraction Successful"
echo "-> Removing $f"
rm $f
else
echo "-> **Extraction Failed"
exit 1
fi
fi
fi
echo ""
i=$(( i+1 ))
done