Skip to content

Instantly share code, notes, and snippets.

@codepunkt
Created November 19, 2012 16:48
Show Gist options
  • Save codepunkt/4111791 to your computer and use it in GitHub Desktop.
Save codepunkt/4111791 to your computer and use it in GitHub Desktop.
find/delete corrupt whisper-files
#!/bin/bash
options=('find' 'delete')
PS3='state your wish: '
echo -e "\nfind/delete corrupt whisper-files"
select opt in "${options[@]}"; do
case $REPLY in
[12] ) option=$opt; break;;
* ) exit;;
esac
done
if [ $option ]; then
matches=()
directory='/opt/graphite/storage/whisper'
for file in $(find $directory -type f -name '*.wsp' -print); do
$(python /usr/local/bin/whisper-info.py $file > /dev/null >2&1)
retval=$?
echo -en "\r\033[Kchecking $file"
[ $retval -ne 0 ] && matches+=($file)
done
if [ $option == 'find' ]; then
echo -en "\r\033[Klisting ${#matches[@]} corrupt files:\n"
for file in "${matches[@]}"; do
echo -e "- $file"
done
else
echo -en "\r\033[Kdeleting ${#matches[@]} corrupt files:\n"
for file in "${matches[@]}"; do
sudo rm $file && echo -e "- $file"
done
fi
fi
@rafaelmagu
Copy link

On L19, >2&1 should actually be 2>&1 in order to redirect stderr to stdout (and, subsequently, to /dev/null)

@garrettwilkin
Copy link

Thanks very much for this! 👍

@pulecp
Copy link

pulecp commented Mar 31, 2016

You should check if /usr/local/bin/whisper-info.py exists otherwise copypasters as me will remove all files ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment