#!/bin/bash # # conn last revised 2/08/2014 # # Script to display / email connected nodes by K0KN 7/2013 # # Usage = conn [Allstar node#] [e] e = email output # # Note: W3m is required for this script to operate. # # CHANGE THESE VARIABLES ONLY # --------------------------- SENDTO="TARGET EMAIL ADDRESS" SENDAS="SENDING EMAIL ADDRESS" SUBJECT="Node $1 html output" LISTURL="http://stats.allstarlink.org/nodeinfo.cgi?node=$1" LOGFILE="/var/log/asterisk/connectlog" FILENAME1="/dev/shm/html_temp" FILENAME2="/dev/shm/html_temp2" if [ "$1" == "" ] ; then echo "Usage = conn [Allstar node#] [e]"; exit fi # Set/Flush variables retrycount=0 TARGET="Error! Cannot open DB file for read" downloadconnlist () { # Download connection list for specified node retrycount=$((retrycount + 1)) if [ $retrycount == 10 ] ; then echo $(date) "conn - Error downloading connection list" >> $LOGFILE ; echo "Error downloading connection list -- exiting" ; exit ; fi w3m -dump -cols 120 $LISTURL > $FILENAME1 ; checklist } checklist () { # Check nodelist for proper header HEADER=$(grep 'Error! Cannot open DB file for read' $FILENAME1) if [ "$HEADER" = "$TARGET" ] ; then echo "Error downloading info" ; downloadconnlist else echo "Info downloaded for node" fi } # Run Check/download nodelist routine downloadconnlist ############################# # Remove statistics from output head --lines=-9 "$FILENAME1" > "$FILENAME2" if ! [ -s "$FILENAME2" ] ; then echo "Node $1 not found" > $FILENAME2 INVALIDNODE="Node not found" fi # Node logging if ! [ "$2" == "e" -o "$2" == "E" ] ; then echo $(date) "conn - Displayed connection html page for node $1 $INVALIDNODE ($retrycount attempts)" >> $LOGFILE clear cat $FILENAME2 exit fi if [ "$2" == "e" -o "$2" == "E" ] ; then echo $(date) "conn - Emailed connection html page for node $1 $INVALIDNODE ($retrycount attempts)" >> $LOGFILE fi # Email results mail -s "$SUBJECT $(date)" $SENDTO -- -f $SENDAS < $FILENAME2 # done rm -f "$FILENAME"1 rm -f "$FILENAME"2 exit 0