#!/bin/ksh # # Requires /etc/hosts to be filled out for any host you want to check name resolution against # #PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin function bomb { echo echo Error: $@ echo exit 1 } function checkhost { # take the first match ip=`grep $1 /etc/hosts | head -1 | awk '{print $1}'` #(( `echo "$ip" | wc -l` > 1 )) && bomb you have more than one entry in /etc/hosts for $1: $ip #stderr slips out already and printing something ahead resolveip=`host $1 | awk '{print $NF}'` (( `echo "$resolveip" | wc -l` > 1 )) && bomb there is more than one record for $1: $resolveip [[ $ip = $resolveip ]] || echo $1 resolves to $resolveip instead of $ip ping -c1 $1 >/dev/null || echo $1 does not respond to ping } #TODO handle timeouts? function checkhttp { tmp=`curl -sI $1 | head -1 | awk '{print $2}'` [[ -z $tmp ]] && echo $1 is down: timeout or bad output [[ ! $tmp = 200 ]] && echo $1 is down: $tmp unset tmp } function checkredir { tmp=`curl -sI $1 | head -1 | awk '{print $2}'` [[ -z $tmp ]] && echo $1 is down: timeout or bad output [[ ! $tmp = 301 ]] && echo $1 is down: $tmp unset tmp } function checkpid { pgrep $1 >/dev/null || echo $1 not running } function checkuserpid { pgrep -u $1 >/dev/null || echo no PID running as user $1 } [[ ! -x `whence host` ]] && bomb host executable not found [[ ! -x `whence curl` ]] && bomb curl executable not found function checkqueue { tmp=`mailq` [[ ! $tmp = "Mail queue is empty" ]] && echo "$tmp" unset tmp } [[ ! -f /root/alive.conf ]] && echo could not read /root/alive.conf && exit 1 . /root/alive.conf # LOCAL (( queue == 1 )) && checkqueue for pid in $pids; do checkpid $pid done; unset pid for pid in $userpids; do checkuserpid $pid done; unset pid # REMOTE #TODO MAKE IT RR CAPABLE e.g. against france* for host in $hosts; do checkhost $host done; unset host for url in $urls; do checkhttp $url done; unset url for redir in $redirs; do checkredir $redir done; unset redir