Skip to content

Instantly share code, notes, and snippets.

@jessereynolds
Last active December 23, 2015 04:19
Show Gist options
  • Save jessereynolds/6579289 to your computer and use it in GitHub Desktop.
Save jessereynolds/6579289 to your computer and use it in GitHub Desktop.
directory size reduced or gone
#!/bin/bash
dir='/private/tmp'
if [ ! -d $dir ] ; then
echo "the directory has gone"
#echo 'body' | mailx -s "the directory has gone" [email protected]
exit 1
fi
if [ -f /tmp/my_dir_size ] ; then
old_size=`cat /tmp/my_dir_size | cut -f 1`
else
old_size=0
fi
new_size=`du -sk $dir | cut -f 1`
echo $new_size > /tmp/my_dir_size
if [[ $old_size -eq 0 ]] ; then
echo "no previous known size"
#echo 'body' | mailx -s "no previous known size" [email protected]
exit 1
fi
new_to_old_ratio=$(awk "BEGIN{print $new_size / $old_size}")
if [[ "$new_to_old_ratio" < '0.9' ]] ; then
echo "new size less than 90% of previous ($new_to_old_ratio)"
#echo 'body' | mailx -s "new size less than 90% of previous" [email protected]
exit 1
fi
echo "new size is $new_to_old_ratio times the previous size"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment