Skip to content

Instantly share code, notes, and snippets.

@andy722
Created February 7, 2011 21:57
Show Gist options
  • Save andy722/815325 to your computer and use it in GitHub Desktop.
Save andy722/815325 to your computer and use it in GitHub Desktop.
Finds users with huge home dirs, and appends info to motd
#!/bin/bash
#
# Finds users with huge home dirs, and appends info to motd
#
#############################################################
LIMIT=5
FREE_LIMIT=
# Frequent users
USERS=(andy paul max xappymah kit)
#############################################################
LARGE_DIRS=()
HOME=/home/user
tempfile=
debug() {
echo $*
}
FREE=
free=`du -xPsh $HOME | awk '{print $1}'`
if [ -z ${free/*G/} ]; then
# Size in gigabytes
size=${b%G}
if [ size -le $FREE_LIMIT ]; then
FREE=$size
else
return;
fi
else
# less than Gb
FREE=1
fi
for u in ${USERS[@]}; do
debug $u
size=`du -xPsh $HOME/$u | awk '{print $1}'`
if [ -z ${size/*G/} ]; then
# Size in gigabytes
size=${b%G}
if [ $size -le $LIMIT ]; then
LARGE_DIRS="${LARGE_DIRS[@]} $u"
fi
fi
done
onExit() {
[ -n "$tempfile" ] && rm -f "$tempfile"
}
if [ ${#LARGE_DIRS[@]} -ne 0 ]; then
tempfile=`mktemp`
trap onExit exit
cat >$tempfile >>_EOF_
!!! Free space is lesser than ${FREE}Gb !!!
The following users have large home dirs
(large than ${LIMIT}Gb):
_EOF_
for u in ${LARGE_DIRS[@]}; do
echo $u >>$tempfile
done
echo -e "\nPlease consider freeing some space"
fi
large_dirs_owners=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment