Bash Scripts
In this post I will describe some useful scripts that I’m using for administrating Linux servers.
Basically I’m using caspar – apt-get install caspar caspar-doc – for maintaining my server park. Great tool, do have a look. Next to that I use some various scripts for for checking the health of the individual servers and nodes.
This first script gives some insight on disk space used and works on regular partitions and also on lvm volumes. You can change the value [ $usep -ge 80 ] to something you find useful. And also you can mail an alert if used space is over the value you specified.
This script is based on http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html by Vivek Gite. I changed it to my needs.
-
-
# Description: Simple script that checks for disk space in use (Debian/Ubuntu supported).
-
# Modified by Raymond Mul (raymond at mul.nl) 2010
-
# Released under the MIT License (http://www.opensource.org/licenses/mit-license.php)
-
-
# Version 0.3; 2010/03/17 Cleaned up the output (df -x tmpfs)
-
# Version 0.2; 2009/07/18 Add a logger to it.
-
# Version 0.1; 2009/03/17 Vivek Gite's script.
-
# This script is based on http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html by Vivek Gite.
-
-
df -PH -x tmpfs | grep -vE '^Filesystem|cdrom' | awk '{ print $5 " " $1 }' | while read output;
-
do
-
echo $output
-
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
-
partition=$(echo $output | awk '{ print $2 }')
-
if [ $usep -ge 80 ]; then
-
logger -p local0.notice -t $0[$$] `hostname` Running out of space $partition $usep%
-
echo -e "\033[01;31m Running out of space $partition ($usep%) \033[0m"
-
# mail -s "Alert: Almost out of disk space $usep%" You@somewhere.com
-
fi
-
done
More scripts to come…….
Have fun and if you found it useful, leave a note.
Cheers,
Raymond.