dannuge
Posts: 5
Joined: Fri Sep 27, 2013 2:48 am

Start up script in sudo

Thu Jun 19, 2014 4:45 pm

Currently to run my program....
1. I power on my pi
2. log in(with password)
3. "cd dirName"
4. "sudo -s"
5. "mavproxy.py" plus args and stuff (its in the system path)

*a password is not required when I use sudo. Not sure why. Maybe because my current user has sudo privileges. Don't fully understand logging in and user privileges. Like what types of things can be run when no user is logged in, i.e. startup???

I want to automate this process. So when I power on my pi, this all occurs without any user intervention. In the end it just needs to run mavproxy.py as a super user. The documentation says to use sudo -s. Not sure why it is necessary. The program runs its own type of terminal environment when it is started, so that may be why.

A nice feature would be able to run all this in a "screen", so then I could ssh into the pi and interact with the program. But that is not necessary.

One last thing. Does the pi have the ability to connect to a lan network(ethernet) after startup? Could I have it run its start routine and then plug in the ethernet later on and ssh into the device?

I have to tried to accomplish this with rc.local but couldn't figure it out. Any suggestions?

Thanks,
Daniel

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Start up script in sudo

Thu Jun 19, 2014 4:51 pm

sudo nano /etc/rc.local

Add
/usr/local/bin/mavproxy.py parms and stuff here &

somewhere before the exit 0 line.

Save and mavproxy.py will get auto started (running with root privileges) when you boot.


BTW, sudo doesn't need a password on Raspbian because someone (who built the distro) decided to update the sudoers file and remove the need to authenticate use of sudo. It may or may not be a good idea, it certainly isn't good for security.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

dannuge
Posts: 5
Joined: Fri Sep 27, 2013 2:48 am

Re: Start up script in sudo

Thu Jun 19, 2014 5:03 pm

Thanks for the quick reply!
I run the program in a specific directory because the program references files in that directory when it runs, so should I change it to

/usr/local/bin/dirName/ mavproxy.py <args>&

??
Otherwise I'll see if I can make the program reference an absolute path.

Luckily this is robotic application so security isn't an issue.

I have seen examples of a screen being run in rc.local like this:

/usr/local/bin/dirName/ screen -d -m -s mavproxy.py <args>&

Any comment on that? I couldn't accurately test it because I wasn't able to successfully launch mavproxy.

Thanks,
Daniel

dannuge
Posts: 5
Joined: Fri Sep 27, 2013 2:48 am

Re: Start up script in sudo

Thu Jun 19, 2014 5:06 pm

I meant couldn't launch mavproxy on my initial attempt. I haven't had a chance to use your proposed method. I dont have access to my pi right now.

plugwash
Forum Moderator
Forum Moderator
Posts: 3630
Joined: Wed Dec 28, 2011 11:45 pm

Re: Start up script in sudo

Sat Jun 21, 2014 2:36 pm

DougieLawson wrote: BTW, sudo doesn't need a password on Raspbian because someone (who built the distro) decided to update the sudoers file and remove the need to authenticate use of sudo. It may or may not be a good idea, it certainly isn't good for security.
Just to clarify the enabling of sudo without password is a characteristic of the raspberry pi foundation raspbian image, not of raspbian in general.

Return to “Raspberry Pi OS”