#!/bin/bash ################################################### ## ## ## disk_free jabber monitoring bot ## ## Author: david@socialnerds.org ## ## v0.2 ## ## ## ################################################### ## timestamp for logfile timestamp=$(date '+%d %B %Y %H:%M') echo "info: starting df bot $timestamp" ## check if sendxmpp is installed if [ $(aptitude search sendxmpp | awk '{print $1}') = "i" ]; then echo "info: sendxmpp found" else if [ $(whoami) = "root" ]; then apt-get install sendxmpp else echo "error: permission denied" echo "info: install sendxmpp or run this scrip as superuser" exit 1 fi fi ## set and load configfile if [ -z $1 ]; then configfile="/etc/mobots/df.conf" if [ -f $configfile ]; then source $configfile else echo "error: no config file $configfile" exit 1 fi else configfile=$1 if [ -f $configfile ]; then source $configfile else echo "error: no config file $configfile" exit 1 fi fi ## check sendxmpp config if [ -f ~/.sendxmpprc ]; then echo "info: jabber config found in ~/.sendxmpprc" else if [ -z $port ]; then port="5222" else echo "info: using port $port" fi echo "$user@$server:$port $pass" > ~/.sendxmpprc chmod 600 ~/.sendxmpprc echo "info: created sendxmpp config in ~/.sendxmpprc" fi ## check disks set -- $disks i="1" for var in "$@" do data=$(df -Ph | grep $var | sed -e 's/%//g' | awk '{print $5}') datathreshold=$(echo $thresholds | awk '{print $'$i'}') if [ $data -gt $datathreshold ]; then echo "info: $var reached threshold with $data%, sending notification to $watchdogs" echo "$hostname: $var is running out of space: $data%" | sendxmpp -r dfbot $watchdogs fi let i++ done ## exiting echo "info: done" exit 0