Skip to content

Instantly share code, notes, and snippets.

@vdloo
Forked from ruuda/scrub.sh
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdloo/b957bdffd4fbf1dc962f to your computer and use it in GitHub Desktop.
Save vdloo/b957bdffd4fbf1dc962f to your computer and use it in GitHub Desktop.
#!/bin/sh
unset MAILTO
unset MAILFROM
DIRECTORY="."
while getopts d:t:f: option
do
case "${option}"
in
d) DIRECTORY=${OPTARG};; # Directory to scrub
t) MAILTO=${OPTARG};; # E-mail for error report
f) MAILFROM=${OPTARG};; # E-mail of who sends the report
esac
done
# Timestamp starting the scrub.
echo -n 'initiating scrub at ' | tee scrub.log
date | tee -a scrub.log
# Enumerate all flac files, run `flac -tsw` (test silent, warning as error) on it,
# and output the filename to scrub.log if it fails.
find $DIRECTORY -type f -name '*.flac' | while read file; do
flac -tsw "$file" && echo "$file is fine" || (echo -e "\e[31m$file is corrupt\e[0m" && echo "$file" | tee -a scrub.log)
done
# And timestamp when it was done.
echo -n 'scrub done at ' | tee -a scrub.log
date | tee -a scrub.log
if [ "$MAILTO" ]; then
if [ "$(cat scrub.log | wc -l)" -gt "2" ]; then
SUBJECT="there are corrupt flacs in the system"
[ "$MAILFROM" ] && (cat scrub.log | mail -s "$SUBJECT" -S from="$MAILFROM" $MAILTO) || (cat scrub.log | mail -s "$SUBJECT" $MAILTO)
fi
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment