-
-
Save vdloo/b957bdffd4fbf1dc962f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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