source: subversion/sites/support/osm-autologger/gpxautologsubmit

Last change on this file was 474, checked in by pere, 14 years ago

First sketch for a script collecting and submitting GPX log files.

File size: 1.2 KB
Line 
1#!/bin/sh
2
3logfile=/var/log/gpsd.gpx
4oldlogs=""
5compressedlogs=""
6
7setlogstart() {
8    logstart=`date +%f` # XXX Select good format for this
9}
10
11istimefornewlog() {
12    logstart="$1"
13    false # XXX Need to figure out good logic for this
14}
15
16# Test if we can contact OSM, and return true if we can
17isOSMreacable() {
18    false
19}
20
21# Check current speed, and return true if we are stipped
22isgpsstopped() {
23    false
24}
25
26# Start logger
27gpxlogger $logfile &
28logpid=$!
29setlogstart()
30
31while true ; do
32
33    # if new day/week, mv logfile logfile.new && kill -HUP $logpid
34    if istimefornewlog "$logstart" ; then
35        mv $logfile $logfile."$logstart" && kill -HUP $logpid
36        oldlogs="$oldlogs $logfile.$logstart"
37        setlogstart()
38    fi
39
40
41    # if wifi zone, and speed == 0, try to submit new files to osm
42    if isOSMreacable() && isgpsstopped() ; then
43        # Compress old logs, if they include the gpx footer,
44        # indicating that gpxlogger started on a new track in a new
45        # file.
46        for log in $oldlogs ; do
47            if tail $log | grep -q '</gpx>' ; then
48                gzip -9 $log
49                compressedlogs="$compressedlogs $log.gz"
50            fi
51        done
52
53        # Try to submit one compressed log file
54        if [ "$compessedlogs" ] ; then
55
56            if osmsubmit $log ; then
57                sentlogs="$sentlogs $logs"
58            else
59            fi
60        fi
61    fi
62    sleep 5
63done
Note: See TracBrowser for help on using the repository browser.