1

So there's a program I am developing and in order to use its full intended functionality, I need it to run with root privileges - otherwise it can't access /dev/spidev0.0. I have to get it to run on system startup with root privileges.

I have created a script that changes into the directory that contains my executable, and runs a terminal instance, passing the command to run the executable as an argument, as in

#!/bin/bash
cd /home/username/app/build
gnome-terminal -- "sudo ./app"

and placed it in Startup Applications. Upon rebooting the board, I get a terminal instance with an error message reading "no such file or directory". Everything runs smoothly, though, should I remove the "sudo" part. The problem is, I need the "sudo".

sudo ./app works just fine if used in terminal when the system has already started. I also tried placing a copy of my executable in /usr/bin and /sbin, and launch them via the script with a gnome-terminal -- "sudo app", to no avail.

How do I properly run an executable on startup with root privileges, if it is at all possible? My version of Ubuntu is 18.04 LTS, if that is of any substance.

1 Answers1

0

The solution that worked for my exact case was to remove the quotes in the command, as pointed out in the comments to the question. Put in the script as

gnome-terminal -- sudo ./app

it worked perfectly. Also got it to launch without prompting a password by adding a line

ALL ALL=(root) NOPASSWD: /home/username/app/build/app

to /etc/sudoers, so the ultimate purpose regarding this question was achieved.