Page 1 of 1

Need help getting this script to run when the RPi starts.

Posted: Mon May 13, 2013 1:34 am
by alfa147x
I need to get this script up and running soon and need a hand.

Code: Select all

#! /bin/sh
sudo gpsd /dev/ttyUSB0 -F /var/run/gpsd.sock
sleep 3
gpspipe -r | grep '^\$G' | tee $nmea
that's the script I need run when the machine boots. Any idea?

I keep getting

Code: Select all

May 12 21:21:45 raspberrypi gpsd[322]: gpsd:ERROR: read-only device open failed: Permission denied
May 12 21:21:45 raspberrypi gpsd[322]: gpsd:ERROR: /dev/ttyUSB0: device activation failed.
when I put it in RC.Local

Thanks for the help,
Alfa

Re: Need help getting this script to run when the RPi starts

Posted: Mon May 13, 2013 2:27 am
by sprinkmeier
/dev/ttyUSB0 probably belongs to the "dialout" group or similar.

To confirm this post the output of

Code: Select all

ls -l /dev/ttyUSB0
groups gpsd
Add the gpsd user to this group

Code: Select all

sudo usermod --append --group dialout gpsd
to give it permission to change that device.

Re: Need help getting this script to run when the RPi starts

Posted: Mon May 13, 2013 3:45 am
by alfa147x

Code: Select all

pi@raspberrypi ~ $ ls -l /dev/ttyUSB0
crw-rw---T 1 root dialout 188, 0 Dec 31  1969 /dev/ttyUSB0
pi@raspberrypi ~ $ groups gpsd
groups: gpsd: No such user
I'll try that 2nd piece you sent me. Thanks!

Edit:

It looks like it didn't work:

Code: Select all

pi@raspberrypi ~ $ sudo usermod --append --group dialout gpsd
usermod: user 'gpsd' does not exist
pi@raspberrypi ~ $ 

Re: Need help getting this script to run when the RPi starts

Posted: Mon May 13, 2013 5:22 am
by sprinkmeier
alfa147x wrote:It looks like it didn't work:

Code: Select all

pi@raspberrypi ~ $ sudo usermod --append --group dialout gpsd
usermod: user 'gpsd' does not exist
pi@raspberrypi ~ $ 
I thought GPSD installed a new user (gpsd) which it drops privelege to after starting as root.

is there anything in the log file about changing UID? maybe to "nobody"?

can you add "pi" to the "dialout" group and pass "-u pi" to the gpsd command?
(from memory, don't have gpsd here right now, that should set UID to "pi" which should work)

Re: Need help getting this script to run when the RPi starts

Posted: Mon May 13, 2013 1:05 pm
by alfa147x
Thanks for the help!
sprinkmeier wrote:
alfa147x wrote:It looks like it didn't work:

Code: Select all

pi@raspberrypi ~ $ sudo usermod --append --group dialout gpsd
usermod: user 'gpsd' does not exist
pi@raspberrypi ~ $ 
I thought GPSD installed a new user (gpsd) which it drops privelege to after starting as root.

is there anything in the log file about changing UID? maybe to "nobody"?

can you add "pi" to the "dialout" group and pass "-u pi" to the gpsd command?
(from memory, don't have gpsd here right now, that should set UID to "pi" which should work)
Hmm. I'll give that a try. If I reinstall GPSD would it try to create the missing user?

Re: Need help getting this script to run when the RPi starts

Posted: Mon May 13, 2013 5:46 pm
by alfa147x
Someone on another forum sent me to this link. I'll be giving it a try tonight as well:
http://unix.stackexchange.com/questions ... tart#25263

Re: Need help getting this script to run when the RPi starts

Posted: Mon May 13, 2013 9:10 pm
by sprinkmeier
alfa147x wrote:Thanks for the help!
Hmm. I'll give that a try. If I reinstall GPSD would it try to create the missing user?

Code: Select all

$ sudo apt-get install gpsd gpsd-clients
$ vi /etc/default/gpsd 
# change START_DAEMON to "true"
$ sudo vi /etc/default/gpsd 
$ sudo /etc/init.d/gpsd start
$ ps auxwww | grep gps
nobody    6796  0.2  0.3   4964  1572 ?        S<s  06:33   0:00 /usr/sbin/gpsd -F /var/run/gpsd.sock -P /var/run/gpsd.pid
pi        6800  0.0  0.1   3544   804 pts/2    S+   06:34   0:00 grep --color=auto gps
Looks like it uses "nobody" on the RasPi. The "gpsd" user might be a mis-remembering on my part or something from an earlier version/different platform.

Read the gpsd man page, esp. "SECURITY AND PERMISSIONS ISSUES".

Try the udev thing, it should work and it's a useful trick to know.