Skip to content

Instantly share code, notes, and snippets.

@vadirajks
Created July 16, 2022 12:37
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 vadirajks/ca7ac8bcd62edd2f0a33fcfc8a686ccd to your computer and use it in GitHub Desktop.
Save vadirajks/ca7ac8bcd62edd2f0a33fcfc8a686ccd to your computer and use it in GitHub Desktop.
find or delete corrupt whisper-files
#!/bin/bash
which whisper-info >/dev/null || {
echo >&2 "'whisper-info' not found: please install"
exit 1
}
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='/var/lib/carbon/whisper'
for file in $(find $directory -type f -name '*.wsp' -print); do
whisper-info $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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment