Autor: @_tty0
Descripción: Script que monitorea el uso de disco.
Visto en tty0
#!/bin/bash # ------------------------------------------------------------------------------------------------------- # set -x # Shell script to monitor or watch the disk space # It will send an email to $ADMIN, if the (free available) percentage of space is >= 90%. # ------------------------------------------------------------------------------------------------------- # Set admin email so that you can get email. ADMIN="somebody@foo.bar" # set alert level 90% is default ALERT=90 # Exclude list of unwanted monitoring, if several partions then use "|" to separate the partitions. # An example: EXCLUDE_LIST="/dev/sdb1|/dev/sdc5" EXCLUDE_LIST="" # #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # date=$(date "+%D %H:%m:%S") function main_prog() { while read output; do usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1) partition=$(echo $output | awk '{print $2}') if [[ $usep -ge $ALERT ]] ; then echo -e "ALERT: $date \n\t Running out of space $partition ($usep%) on server: $(hostname)" | \ mail -s "AACREA Alert: $(hostname) Almost out of disk space $usep%" $ADMIN logger -p local7.warn "Running out of space $partition ($usep) - Email sent to $ADMIN" fi done } if [ "$EXCLUDE_LIST" != "" ] ; then df -H | grep -vE "^Filesystem|tmpfs|cdrom|${EXCLUDE_LIST}" | awk '{print $5 " " $6}' | main_prog else df -H | grep -vE "^Filesystem|tmpfs|cdrom" | awk '{print $5 " " $6}' | main_prog fi
Permisos: chmod 700 email-alertfs.bash
Ejecución: ./email-alertfs.bash
0 comentarios:
Publicar un comentario