#!/bin/bash # # elrandom v4.2, last updated 11/26/2019 # # Script to connect to a random Echolink node, by K0KN 2/2011 # # Usage = elrandom [your node#] [2] [3] ; 2=monitor only 3=transceive # # Note: W3m is required to create node list. Install w3m with apt-get or yum if necessary # # The "echolinkrandom" and other custom audio files are available via WGET: # wget www.qsl.net/k0kn/k0kn_extra_sounds.tgz # # You can place any node numbers that you do not wish to dial in the DENYLIST file specified below, one per line. Do not # leave any blank lines in this file. For example: (do not include the # of course) # # 327890 # 009999 selectattempt=3 # Set this number to the maximum number of attempts you would like this script to make CUSTOM=/dev/shm LISTURL="http://www.echolink.org/logins.jsp" LOGFILE="/var/log/asterisk/connectlog" NODELIST="/dev/shm/echolink_nodelist" DENYLIST="/home/kyle/elrandom_deny" RANDOMSOUND="/etc/asterisk/sounds/echolinkrandom" ERRORSOUND="/var/lib/asterisk/sounds/an-error-has-occurred" retrycount=0 selectcount=0 denynode="" LOCALNODE=$1 if [ "$1" == "" -o "$2" == "" ] ; then echo "Usage = elrandom [your node#] [2] [3]"; exit fi if ! [ -f $DENYLIST ] ; then touch $DENYLIST fi ############################################# downloadnodelist () { # Create / update local nodelist retrycount=$((retrycount + 1)) if [ $retrycount == 10 ] ; then echo $(date) "Error downloading Echolink nodelist" >> $LOGFILE ; echo "Error downloading nodelist -- exiting" ; exit ; fi if ! [ -f $NODELIST ] ; then echo "No nodelist found - downloading" ; w3m -dump -cols 120 $LISTURL > "$NODELIST"2 ; checknodelist cp "$NODELIST"2 $NODELIST fi if [ "$(( $(date +"%s") - $(stat -c "%Y" $NODELIST) ))" -gt "1800" ] then echo "Nodelist over 30 minutes old - downloading new" w3m -dump -cols 120 $LISTURL > "$NODELIST"2 ; checknodelist fi } checknodelist () { # Check nodelist for proper header HEADER=$(grep 'Current Logins' "$NODELIST"2) if [ "$HEADER" != "" ] ; then echo "Header check complete" else echo "Header does not match" ; downloadnodelist fi # Check nodelist for proper footer FOOTER=$(grep '[Conferences]' "$NODELIST"2) if [ "$FOOTER" != "" ] ; then echo "Footer check complete" else echo "Footer does not match" ; downloadnodelist fi # Remove header if [ -f "$NODELIST"2 ] then awk 'FNR>13{print}' "$NODELIST"2 > $NODELIST fi # Remove footer if [ -f "$NODELIST"2 ] then sed '/^$/d' $NODELIST > "$NODELIST"2 sed '$d' < "$NODELIST"2 > $NODELIST cut -c30-88 $NODELIST > "$NODELIST"2 cp "$NODELIST"2 $NODELIST rm -f "$NODELIST"2 fi } selectrandom () { selectcount=$((selectcount + 1)) denynode="" echo "selectcount: $selectcount" if [ $selectcount -gt $selectattempt ] ; then echo $(date) "Random Echolink script - attempt $selectcount. Maximum $selectattempt. Giving up" >> $LOGFILE asterisk -rx "rpt localplay $LOCALNODE $ERRORSOUND" echo "Attempt $selectcount. Maximum $selectattempt. Giving up" ; exit fi # Count number of stations listed wc -l "$NODELIST" > "$CUSTOM"/el_random_count LINES=$(cut -d " " -f1 "$CUSTOM"/el_random_count) LINES=$(( $LINES - 2 )) echo "" echo "Number of logged in nodes: $LINES" # Generate Random Line # between 1 and number of lines in file RAN_NODE=$[ ( $RANDOM % $LINES ) + 1 ] echo "random number =" $RAN_NODE # Copy Random line to temp file sed -n ""$RAN_NODE"p" "$NODELIST" > "$CUSTOM"/el_random_node # Parse temp file CALLSIGN=$(cut -c 1-10 "$CUSTOM"/el_random_node) node_num=$(cut -c 54-59 "$CUSTOM"/el_random_node) NODENAME=$(cat "$CUSTOM"/el_random_node) echo $node_num > "$CUSTOM"/random_enode_dialed # Remove whitespaces node_num=$(echo $node_num | tr -d ' ') callsign=$(echo $callsign | tr -d ' ') # Expand node number to 6 digits node_num=$(printf "%06d\n" $node_num) # node_num=$(awk '{printf "%006s\n", $0}' "$CUSTOM"/random_enode_dialed) echo $node_num > "$CUSTOM"/random_enode_dialed # Display to console echo "callsign =" $CALLSIGN echo "node_num =" $node_num echo "" # checkdeny } checkdeny () { # Check to see if random node is in deny list while IFS= read -r line do echo "Deny node: $line" if [ "$line" = "$node_num" ] ; then echo "Random node in deny list! Denied node - $node_num $CALLSIGN" echo $(date) "Random Echolink script - denied node $node_num ($CALLSIGN) $NODENAME" >> $LOGFILE denynode="deny" fi done < $DENYLIST # if [ "$denynode" = "deny" ] ; then selectrandom fi } ########################################### asterisk -rx "rpt localplay $LOCALNODE $RANDOMSOUND" # Delete nodelist if zero bytes if ! [ -s $NODELIST ] ; then rm -f $NODELIST ; fi # Run Check/download nodelist routine downloadnodelist # Select random station selectrandom ############################### # Node logging echo $(date) "Random Echolink script - $1 called $ECHOINFO $NODENAME" >> $LOGFILE # Make Call echo "Sending command: rpt fun $1 *$23$node_num" asterisk -rx "rpt fun $1 *$23$node_num" sleep 2 exit 0