#!/bin/bash myUsername="Guest" ST_OK=0 ST_WR=1 ST_CR=2 ST_UK=3 if [ -z "$1" ]; then echo "check_smbsize written by Charles Shortridge (cshortridge at gmail.com)" echo "Usage: check_smbsize -H Host -S Share [-U username] [-P password] [-W Warning] [-C Critical]" echo " -H " echo " Specify the SMB Host to connect to" echo " -S " echo " Specify the SMB Share" echo "Optional:" echo " -U" echo " The Username to use" echo " -P" echo " The Password to use" echo " -W " echo " The available % free to signal a warning" echo " -C " echo " The available % free to signal a critical" echo "" exit fi while test -n "$1"; do case "$1" in -H) myHost=$2 shift ;; -S) myShare=$2 shift ;; -U) myUsername=$2 shift ;; -P) myPassword=$2 shift ;; -W) myWarn=$2 shift ;; -C) myCrit=$2 shift ;; *) echo "Error: Unknown argument $1" exit ;; esac shift done if [ -z "$myHost" ]; then echo "Hostname is required" exit fi if [ -z "$myShare" ]; then echo "Share is required" exit fi if [ -z "$myPassword" ]; then myUsername="$myUsername -N" fi blocksline=$(smbclient -U $myUsername -c du //$myHost/$myShare $myPassword | grep blocks) numblocks=$(echo $blocksline | cut -d' ' -f1) blocksize=$(echo $blocksline | cut -d' ' -f5 | tr -d .) freeblocks=$(echo $blocksline | cut -d' ' -f6) if [ -z $numblocks ]; then echo "Error: Check Username/Password" exit fi totalM=$(echo $numblocks*$blocksize/1024/1024|bc) freeM=$(echo $freeblocks*$blocksize/1024/1024|bc) freeper=$(echo "scale=2;$freeM/$totalM*100"|bc) if [ -n "$myCrit" ]; then dowarn=$(echo "$myCrit >= $freeper"|bc) if [ $dowarn -eq "1" ]; then echo "Critical: Total: ${totalM}MB - Free: ${freeM}MB ($freeper%) (Critical Threshold: ${myCrit}%)" exit $ST_CR fi fi if [ -n "$myWarn" ]; then dowarn=$(echo "$myWarn >= $freeper"|bc) if [ $dowarn -eq "1" ]; then echo "Warning: Total: ${totalM}MB - Free: ${freeM}MB ($freeper%) (Warning Threshold: ${myWarn}%)" exit $ST_WR fi fi echo "OK: Total: ${totalM}MB - Free: ${freeM}MB ($freeper%)" exit $ST_OK