NAS Backup Server Disk Monitoring Shell Script
- Details
- Category: Backup Systems
- Written by Mahdi Bahmani Ciahmard
- Hits: 74
NAS Backup Server Disk Monitoring Shell Script
#!/bin/bash
# Shell Script to monitor NAS backup disk space
# Shell script will mount NAS using mount command and look for total used
# disk space. If NAS is running out of disk space an email alert will be sent to
# admin.
# -------------------------------------------------------------------------
# Copyright (c) 2004 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
#!/bin/bash
#*** SET ME FIRST ***#
NASUSER="Your-User-Name"<br />NASPASS="Your-Password"<br />NASIP="nas.yourcorp.com"<br />NASROOT="/username"<br />NASMNTPOINT="/mnt/nas"<br />EMAILID="
This e-mail address is being protected from spambots. You need JavaScript enabled to view it.
"<br /> <br />GETNASIP=$(host ${NASIP} | awk '{ print $4}')<br /> <br /># Default warning limit is set to 17GiB<br />LIMIT="17"<br /> <br /># Failsafe<br />[ ! -d ${NASMNTPOINT} ] && mkdir -p ${NASMNTPOINT}<br />mount | grep //${GETNASIP}/${NASUSER}<br /> <br /># if not mounted, just mount nas<br />[ $? -eq 0 ] && : || mount -t cifs //${NASIP}/${NASUSER} -o username=${NASUSER},password=${NASPASS} ${NASMNTPOINT}<br />cd ${NASMNTPOINT}<br /> <br /># get NAS disk space<br />nSPACE=$(du -hs|cut -d'G' -f1)<br /># Bug fix<br /># get around floating point by rounding off e.g 5.7G stored in $nSPACE<br /># as shell cannot do floating point<br />SPACE=$(echo $nSPACE | cut -d. -f1)<br /> <br />cd /<br />umount ${NASMNTPOINT}<br /> <br /># compare and send an email<br />if [ $SPACE -ge $LIMIT ]<br />then<br /> logger "Warning: NAS Running Out Of Disk Space [${SPACE} G]"<br /> mail -s 'NAS Server Disk Space' ${EMAILID} <<EOF<br />NAS server [ mounted at $(hostname) ] is running out of disk space!!!<br />Current allocation ${SPACE}G @ $(date)<br />EOF<br />else<br /> logger "$(basename $0) ~ NAS server ${NASIP} has sufficent disk space for backup!"<br />fi</p> <p style="text-align: left;"></p>
<p style="text-align: left;">
source:http://bash.cyberciti.biz/backup/monitor-nas-server-unix-linux-shell-script/

