#!/bin/bash ######################################################################## # filename: random_call # # description: Places a call to a randomly selected IRLP node # NOTE: I did not provide for playing an anouncement that # a random call was being made. Took more time to play the # announcement than to make the selection and connection. # # history: # 20020310 g4cui Original release # 20020311 kc6hur Cleaned up program flow and added check for # local node selected. # 20020314 kc6hur Added lockout_list check and conditional play of # random_node.wav # 20020724 kc6hur Added check for active # 20021018 kc6hur Works for 4-digit node numbers # 20021027 kc6hur Modified to use nohtmlstatus.txt # 20021202 kc6hur Modified to cache nohtmlstatus.txt and fixed a # problem handling the format of nohtmlstatus.txt # Added code to handle the legacy 3-digit nodes. ######################################################################## # # Convenience functions # # Send message to LOGFILE function log () { MESSAGE=$@ if [ -n "$LOGFILE" ]; then echo "`date '+%b %d %Y %T %z'` ${0##*/}: $MESSAGE" >> $LOGFILE fi } ####################################################################### # # Standard Script Opening # # Make sure we are user repeater!!! if [ `/usr/bin/whoami` != "repeater" ] ; then echo This program must be run as user REPEATER! exit 1 fi # Make sure we have sourced the environment file if [ "$RUN_ENV" != "TRUE" ] ; then . /home/irlp/custom/environment fi # # Make sure a connection is not already in progress # if [ -f ${LOCAL}/active ] ; then echo The node is already in an active link! exit 1 fi # # Make sure a lockout_list file exists even if it is empty # if [ ! -f ${CUSTOM}/lockout_list ] ; then echo -n "Creating ${CUSTOM}/lockout_list..." touch ${CUSTOM}/lockout_list echo "DONE" fi # # Play the optional random_node.wav file # if [ -f ${AUDIO}/custom/random_node.wav ] ; then ${BIN}/key usleep ${TXDELAY:-500000} play ${AUDIO}/custom/random_node.wav usleep 500000 ${BIN}/unkey fi # # Grab and cache the nohtmlstatus.txt file # /usr/bin/wget -O /tmp/status_cache http://status.irlp.net/nohtmlstatus.txt # # Tweak the old 3-digit node numbers # if [ ${#STATIONID} -eq 6 ] ; then LCLNODE=${STATIONID}0 else LCLNODE=${STATIONID} fi # # Make random node selection and call that node # RANDOM=$(date +%s) # Seed the random number generator d=$[ ( RANDOM % 8000 ) + 1000 ] # Generate a random node number TRIES=1 while [ `grep -c stn${d} ${LOCAL}/hosts` -eq 0 ] \ || [ stn${d} = ${LCLNODE} ] \ || [ `grep -c stn${d} ${CUSTOM}/lockout_list` -ne 0 ] \ || [ `grep ^${d} /tmp/status_cache | grep -c IDLE` -eq 0 ] ; do d=$[ ( RANDOM % 8000 ) + 1000 ] # Generate another random node number let TRIES=${TRIES}+1 # Bump the loop count done log "random_call to stn${d} after ${TRIES} attempt(s)" ${SCRIPT}/call stn${d} # Call the valid randomly selected node exit 0 # Return to custom_decode