Friday, July 31, 2020

Restart gpsd on a daily basis using expect!

cron…

26 3 * * * /root/bin/startgpsd.sh >> /var/log/startgpsd.log
# Run Monthly at the 9th day for Leap second file
#
#20 2 9 * * /usr/bin/update-leap >> /var/log/update.leap.second.log

which runs a shell script which calls an expect script.

#!/bin/sh -e
#######################################################################
# LED Pin - wiringPi pin 0 is BCM_GPIO 17.   (Physical pin 11)
#
DATE=`/bin/date`
echo "========================================================================"
echo $DATE
/root/bin/startgpsd.exp
root@ntpd1:~/bin# cat startgpsd.exp
#!/usr/bin/expect -f

spawn $env(SHELL)
match_max 100000

send -- "cd /etc/rc.d/r"
expect -exact "#"

send -- "./rc.gpsd stopr"
expect -exact "#"

send -- "./rc.gpsd stopr"
expect -exact "#"

send -- "./rc.gpsd startr"
expect -exact "#"

send -- "exitr"
expect eof
root@ntpd1:~/bin#