Skip to content

Instantly share code, notes, and snippets.

@revol
Created September 25, 2014 20:02
Show Gist options
  • Save revol/5246d09baca7b9ccbc6a to your computer and use it in GitHub Desktop.
Save revol/5246d09baca7b9ccbc6a to your computer and use it in GitHub Desktop.
## Set date with GPS
## reV 2014-09-25
GPS="/dev/ttyUSB0"
LAST="/sd/logs/date.last"
if [[ ! -e $GPS ]]; then
echo $GPS not found!
echo check last known date
if [[ -e $LAST ]]; then
GPSDATE=$(cat $LAST)
else
echo $LAST not found!
GPSDATE="2014-01-01 00:00:00"
fi
else
GPSDATE=$(gpspipe -w -n 10 | grep TPV | sed -r 's/.*"time":"([^"]*)".*/\1/' | tail -n 1 | sed -e 's/^\(.\{10\}\)T\(.\{8\}\).*/\1 \2/')
echo $GPSDATE > $LAST
fi
date -us "$GPSDATE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment