#!/bin/sh # script to output the APRX log data (APRS data received via RF/inet) to the display. # the process in this script runing in a loop: # 1) check if APRX runs still by checking existence of APRX_PID file. # 2) check if there is a difference between APRXRF_LOG / APRX_LOG and PRXRF_LOG_TMP / APRX_LOG_TMP. # 3a) if there is a difference send result to display. # 3b) make a copy of log file APRXRF_LOG / APRX_LOG and APRXRF_LOG_TMP / APRX_LOG_TMP. # 4) if there is no difference do nothing. # 5) continue with step 1). local NAME local DISPLAY local SOURCE local APRX_LOG local APRXRF_LOG local APRX_LOG_TMP local APRXRF_LOG_TMP # variable definitions NAME="aprs_log_loop" DISPLAY="/dev/Display" APRX_LOG="/var/log/aprx/aprx.log" APRXRF_LOG="/var/log/aprx/aprx-rf.log" APRX_LOG_TMP="/tmp/.aprx.log" APRXRF_LOG_TMP="/tmp/.aprx-rf.log" APRX_PID="/var/run/aprx.pid" THIS_SCRIPT_PID="/var/run/display_aprx_log_loop.pid" # generate the log files if they do not exist yet. touch $APRX_LOG_TMP touch $APRXRF_LOG_TMP touch $APRX_LOG touch $APRXRF_LOG # check if this script is not yet running by checking existence of THIS_SCRIPT_PID if [ ! -f $THIS_SCRIPT_PID ]; then # create the THIS_SCRIPT_PID file to indicate the running process touch $THIS_SCRIPT_PID # send message to display that the log output is started echo "APRX log start:" > $DISPLAY # write to system log that the log output is started logger -t "$NAME" "APRX log display start" # run this loop as long as the APRX program is running while [ -f $APRX_PID ]; do # check if there is a difference between APRXRF_LOG and APRXRF_LOG_TMP if [[ "$(diff -q $APRXRF_LOG $APRXRF_LOG_TMP)" == "Files $APRXRF_LOG and $APRXRF_LOG_TMP differ" ]]; then # difference found; send out difference to Display diff $APRXRF_LOG $APRXRF_LOG_TMP | awk '/^-/ && !/^---/ { $1=""; print }' > $DISPLAY # copy APRXRF_LOG into APRXRF_LOG_TMP to avoid difference in next loop and dublicate output. cp -f $APRXRF_LOG $APRXRF_LOG_TMP fi # check if there is a difference between APRX_LOG and APRX_LOG_TMP if [[ "$(diff -q $APRX_LOG $APRX_LOG_TMP)" == "Files $APRX_LOG and $APRX_LOG_TMP differ" ]]; then # difference found; send out difference to Display diff $APRX_LOG $APRX_LOG_TMP | awk '/^-/ && !/^---/ { $1=""; print }' > $DISPLAY # copy APRX_LOG into APRX_LOG_TMP to avoid difference in next loop and dublicate output. cp -f $APRX_LOG $APRX_LOG_TMP fi done # loop exit due to APRX not running anymore. echo "APRX stopped" > $DISPLAY # remove THIS_SCRIPT_PID to indicate that script has stopped working. rm -f $THIS_SCRIPT_PID # send message to display that output has stopped. echo "APRX log-display stopped" > $DISPLAY # write system log entry that output has stopped. logger -t "$NAME" "APRX log-display stopped" # exit the script else # send message to display that log output is already running. echo "APRX log-display already running" > $DISPLAY # write system log entry that log output is already running. logger -t "$NAME" "APRX log-display already running" fi # exit the script #diff -q $APRXRF_LOG $APRXRF_LOG_TMP <- delivers if there is a difference yes/no. #diff $APRXRF_LOG $APRXRF_LOG_TMP <- delivers the difference between the two files. #awk '/^-/ && !/^---/ { $1=""; print }' <- removes the trailing "-" characters from the difference output.