1

I have been trying to get my script run right after I reboot. I have tried editing the rc.local file without success. After that I tried to add an entry to Startup Applications with the path to my script /home/user/Scripts/myScript.sh.

Then my system rebooted running the wanted script. The problem obviously isn't with execution privileges (which I've added with chmod command) but with denied access, because the command was not run with root privileges. Since gksu and gksudo is no longer supported, I was wondering how could I work around this problem.

I am running Ubuntu 18.04, 64-bit

I also now found, that running rc.local does run the script, however it does not run on startup

Permissions of the script:

user@d4tor:~$ ll /home/user/Scripts/myScript.sh
-rwx--x--x 1 user user 129 July  3 16:50 /home/user/Scripts/myScript.sh*

Permissions of rc.local:

user@d4tor:/etc$ ls -l rc.local
-rwxr-xr-x 1 root root 328 July  5 17:45 rc.local
5
  • adding it to your root user's crontab might do the trick.
    – veras
    Jul 5, 2018 at 0:46
  • 1
    How do you know startup applications ran the script? Can you update your question with the output from ll /home/user/Scripts/myScript.sh and cat /home/user/Scripts/myScript.sh? Jul 5, 2018 at 1:26
  • 1
    /etc/rc.local will absolutely certainly be run as root upon system startup, if it exists and it is executable. You may be making a confusion between system startup and the start of a graphical session for a user. (A system can run happily without having any user loggen in in a graphical session.) They are not the same thing, and do not run the same scripts. There is very little reason to run a script as root in a user's graphical session; there is never any good reason to run a GUI program as root.
    – AlexP
    Jul 5, 2018 at 5:28
  • @WinEunuuchs2Unix I am certain of it because my script launches a gnome-terminal and excecutes commands there. As I put the script path into rc.local, nothing happened but after I added it into startup applications it ran the terminal but asking me for permissions. The script is also excecutable because I have checked the permissions of rc.local and the script I use. The rc.local also runs just fine opening a terminal when I manually run rc.local. Jul 5, 2018 at 14:29
  • I don't know why you would want/need to run a gui program at startup. However if you really want to, gui programs now need to use pkexec to run as root. You can read the first answer here: askubuntu.com/questions/383747/… to see how to let a program use pkexec without password, and then your script should work.
    – SudoSURoot
    Jul 5, 2018 at 15:02

1 Answer 1

0

Make script readable

Your script is only readable by the owner. The first step (just to be safe) would to make it readable by everyone:

chmod a+r /home/user/Scripts/myScript.sh

If that doesn't solve your issues, please update your question with the actual contents of your script.

1
  • Ill try that. just to be safe ill add a+rwx to the script Jul 5, 2018 at 23:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .