#!/bin/bash # This function is deprecated. # Use gpsd_settime instead. # PPS= 1484247472.29561104 clock= 1484247990.00000000 offset= 517.704388959 # DEBUG=1 to set debug NAME=gpsd_ubx_settime shopt -s expand_aliases alias LG="logger -t $NAME" function kill_it { cmd=$1 pid=$2 sig=$3 ((DEBUG)) && LG -p user.info "terminating $cmd(${pid}) with SIG${sig}" kill -SIG${sig} ${pid} result=$? ((DEBUG)) && LG -p user.info "kill -SIG${sig} ${pid} result is $result" } trap "stty echo icanon" exit OIFS=$IFS IFS=$'\n' if ! /usr/sbin/gpsd_ubx_fixed &1 | ( while read ln ; do if [[ $ln =~ ^[[:space:]]*PPS=.*clock=[[:space:]]*([0-9]*)\. ]] ; then echo ${BASH_REMATCH[1]} break fi done )) if [[ $epoch =~ ^[0-9]+$ ]] ; then LG -p user.warn "Updating time to epoch time, ${epoch}." date +%s -s @${epoch} >/dev/null else LG -p user.err "gpsmon output is bad." exit 1 fi exit 0