0

I am trying to get a gpxlogger running after booting up RaspPi, the problem is that gpxlogger automatically shuts down after 5 seconds if there is no signal from GPSD on startup (which gets the signal around 1,5-2 minutes after boot, sometimes more so sleep would probably not solve it), and if that happens, it returns with a 0.

So far I've got:

(while true; do
     until gpxlogger -d -f /home/pi/gpslogs/log'%Y-%m-%d-%H:%M:%S'.txt -i 2; do
         echo "restarting"
         sleep 10
     done
done
) &

in /etc/init.d/rc.local

The problem is, the script doesn't wait for the gpxlogger to return, but starts a new gpxlogger every 10 seconds.

tl;dr Desired action:

Start up Raspberry -> Loop gpxloggers dying after 5 seconds of no data from GPSD -> Get fix in GPSD -> Single gpxlogger keeps logging into file

Could someone try to help me with this? Any input would be appreciated.

Rachey
  • 211
  • 2
  • 9

1 Answers1

1

Don't restart if it's already running.

while true; do
    if ! pidof gpxlogger >/dev/null; then
        echo "restarting"
        gpxlogger -d -f /home/pi/gpslogs/log'%Y-%m-%d-%H:%M:%S'.txt -i 2
    fi
    sleep 10
done &

(The parentheses appear to be superfluous, so I removed them.)

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Works like a charm! Thanks! – Rachey Jan 08 '16 at 11:07
  • You seem to be assuming that `%H` et al will be substituted with the current hour etc. That's not a feature of the normal Unix shell; you probably want to interpolate `date` like `/home/pi/gpslogs/log$(date +%F-%T).txt` – tripleee Jan 08 '16 at 11:09
  • The format I use seems to work fine on Raspbian- the files are named correctly, but thanks for the input. – Rachey Jan 08 '16 at 11:25
  • Oh, maybe `gpxlogger` makes the substitution. – tripleee Jan 08 '16 at 11:26
  • Quite possible- I found the date format on gpxlogger-related question on raspberry forums. – Rachey Jan 08 '16 at 11:29