Monitor NAS Space
This handy script can be run daily to monitor how much storage you have left. You will find this most useful when you are leasing space in a VPS environment such as slice host or the like. I added email to the script to send an alert when things go awry
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #!/bin/bash #*** SET ME FIRST ***# NASUSER="Your-User-Name" NASPASS="Your-Password" NASIP="nas.yourcorp.com" NASROOT="/username" NASMNTPOINT="/mnt/nas" EMAILID="admin@yourcorp.com" #*** END SET ME ***# GETNASIP=$(host ${NASIP} | awk '{ print $4}') # Default warning limit is set to 17GiB LIMIT="17" # Failsafe [ ! -d ${NASMNTPOINT} ] && mkdir -p ${NASMNTPOINT} mount | grep //${GETNASIP}/${NASUSER} # if not mounted, just mount nas [ $? -eq 0 ] && : || mount -t cifs //${NASIP}/${NASUSER} -o username=${NASUSER},password=${NASPASS} ${NASMNTPOINT} cd ${NASMNTPOINT} # get NAS disk space nSPACE=$(du -hs|cut -d'G' -f1) # Bug fix # get around floating point by rounding off e.g 5.7G stored in $nSPACE # as shell cannot do floating point SPACE=$(echo $nSPACE | cut -d. -f1) cd / umount ${NASMNTPOINT} # compare and send an email if [ $SPACE -ge $LIMIT ] then logger "Warning: NAS Running Out Of Disk Space [${SPACE} G]" mail -s 'NAS Server Disk Space' ${EMAILID} <<EOF NAS server [ mounted at $(hostname) ] is running out of disk space!!! Current allocation ${SPACE}G @ $(date) EOF else logger "$(basename $0) ~ NAS server ${NASIP} has sufficent disk space for backup!" fi |



you bohbah!