#!/bin/bash # # Astrandom v3, last revised 4/4/2013 # # Script to connect to a random Allstar Node, by K0KN 2/2011 # # Usage = astrandom [your node#] [0] [2] [3] ; 0 = update list only 2 = monitor only, 3 = transceive # # Note: Lynx is required to create node list. # # The "20plus" and "allstarrandom" 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) # # 2000 # 2001 # 29000 CUSTOM=/dev/shm LOGFILE="/var/log/asterisk/connectlog" DENYLIST="/home/kyle/astrandom_deny" FILENAME1="/dev/shm/astrandom.x1" FILENAME2="/dev/shm/astrandom.x2" SOUNDS="/etc/asterisk/sounds" if [ "$1" == "" ] ; then echo "Usage = astrandom [your node#] [0] [2] [3]"; exit fi if [ "$2" == "" ] ; then echo "Usage = astrandom [your node#] [0] [2] [3]"; exit fi if ! [ -f $DENYLIST ] ; then touch $DENYLIST fi # Clean up old temp files if [ -f "$CUSTOM"/random_list ] then rm "$CUSTOM"/random_list fi if [ -f "$CUSTOM"/random_temp ] then rm "$CUSTOM"/random_temp fi if [ -f "$CUSTOM"/random_count ] then rm "$CUSTOM"/random_count fi # asterisk -rx "rpt localplay $1 $SOUNDS/allstarrandom" # Download current Allstar node list lynx -dump -nolist http://stats.allstarlink.org/ > "$CUSTOM"/random_temp # Remove header awk 'FNR>7{print}' "$CUSTOM"/random_temp > "$CUSTOM"/random_list rm -f "$CUSTOM"/random_temp # Count number of stations listed wc -l "$CUSTOM"/random_list > "$CUSTOM"/random_count LINES=$(cut -d " " -f1 "$CUSTOM"/random_count) LINES=$(( $LINES - 2 )) echo "Number of logged in nodes: $LINES" # Remove whitespaces cat "$CUSTOM"/random_list | sed 's/^[ \t]*//;s/[ \t]*$//' > "$CUSTOM"/random_temp rm -f "$CUSTOM"/random_list # Remove footer head -n$LINES "$CUSTOM"/random_temp > "$CUSTOM"/random_list2 # Clean up Temp Files rm -f "$CUSTOM"/random_temp rm -f "$CUSTOM"/random_count # Remove uptime etc awk -F" " '{for(i=0;++i<=NF-5;)printf $i" ";print $(NF-4)}' "$CUSTOM"/random_list2 > "$CUSTOM"/random_list # 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" "$CUSTOM"/random_list > "$CUSTOM"/random_node # Parse temp file node_num=$(cut -c 1-5 "$CUSTOM"/random_node) echo "node number =" $node_num echo $node_num > "$CUSTOM"/random_anode_dialed if [ "$2" == "0" ] ; then echo "Update list only" exit fi # 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 $node_num in deny list! Exiting!" echo $(date) "Random Allstar script - denied node $node_num" >> $LOGFILE asterisk -rx "rpt localplay $1 $SOUNDS/nodedeny" exit fi done < $DENYLIST # Node logging echo $(date) "Random Allstar script - called node $node_num" >> $LOGFILE echo "" # Make Call echo "rpt fun $1 *$2$node_num" asterisk -rx "rpt fun $1 *$2$node_num" sleep 2 # Get list of all connected nodes asterisk -rx "rpt nodes $1" > $FILENAME1 if ! [ -f $FILENAME1 ] ; then touch $FILENAME1 fi if grep -q "" $FILENAME1 ; then rm -f $FILENAME1 touch $FILENAME1 fi # Remove banner and blank lines cat $FILENAME1 | grep -v "*" > $FILENAME2 if [ -f $FILENAME2 ] ; then sed '/^$/d' $FILENAME2 > $FILENAME1 fi # Count number of connected nodes TOTALCOUNT=($( wc -w $FILENAME1)) echo "Total connected nodes: $TOTALCOUNT" # Speak number of connected nodes if [ $TOTALCOUNT -lt 21 ] then asterisk -rx "rpt localplay $1 /var/lib/asterisk/sounds/digits/$TOTALCOUNT" fi if [ $TOTALCOUNT -gt 20 ] then asterisk -rx "rpt localplay $1 $SOUNDS/20plus" fi # done exit 0 fi