Ask / Submit
1

autostart bash script as root

asked 2014-01-16 22:36:00 +0200

jayki gravatar image

updated 2014-01-18 14:05:52 +0200

lk gravatar image

Hey ;) Does somebody know how to autostart a bash script as root? If i put a .desktop in /etc/xdg/autostart which runs the script it only works as nemo user.. I search for a way to start my script as root, so that i don't need to start it every time i reboot in terminal... I need thsi, because bind mount only works as root :/ Thanks :)

edit retag flag offensive close delete

Comments

Did you consider creating a systemd service which would run your script?

strnous ( 2014-01-17 00:15:24 +0200 )edit

I'll try this in /lib/systemd

jayki ( 2014-01-17 01:10:51 +0200 )edit

@jayki It is not just placing your script in /lib/systemd which needs to be done. Please, see i.e. here and/or here

strnous ( 2014-01-17 09:01:22 +0200 )edit

2 Answers

Sort by » oldest newest most voted
3

answered 2014-02-25 23:59:45 +0200

alex gravatar image

updated 2014-02-26 00:22:37 +0200

I wrote a simple service with a small explanation for another answer to another question in this forum. See here:

https://together.jolla.com/question/1171/reduce-display-brightness/#post-id-30517

You can use it as an example or starting point for creating your own service file and starting your own shell script with root required commands. Perhaps it helps ...

edit flag offensive delete publish link more
0

answered 2015-06-19 22:12:06 +0200

V10lator gravatar image

updated 2015-06-19 22:16:05 +0200

Another way could be to use sudo.

  1. Install sudo (as root): pkcon install sudo
  2. Install some editor (as root), for example: pkcon install nano
  3. Open visudo with your editor (as root): EDITOR="nano" visudo
  4. Add a line like this: nemo ALL=(ALL) NOPASSWD: /home/nemo/rootstart.sh
  5. Create the script /home/nemo/rootstart.sh(as root) and make it executable (chmod +x). This file will be executed as root later on.
  6. Create another script, like for example /home/nemo/autostart.sh with the following content:
#!/bin/sh

# Add some code which should be executed as nemo here if you like...
echo "Gaining root rights..."

# Finally become root:
sudo /home/nemo/rootstart.sh

That's it. Now execute /home/nemo/autostart.sh however you like (directly, by /etc/xdg/autostart/something.desktop / as systemd user service / ...).

edit flag offensive delete publish link more
Login/Signup to Answer

Question tools

Follow
3 followers

Stats

Asked: 2014-01-16 22:36:00 +0200

Seen: 1,076 times

Last updated: Jun 19 '15