1

I made a script that controls my system LEDs and it works great. I saved it to /usr/local/bin/led-pattern and ran sudo chmod a+x /usr/local/bin/led-pattern so its executable simply by entering the command led-pattern. Upon doing so, it asks for an administrative password, and upon entering the password, the script runs as intended. However, when added to my list of startup applications, it does not run at login, presumably because of the lack of sudo permissions, as all my other startup scripts that I've made work just fine and don't require permission. How can I make it so that this script runs at startup seamlessly - never asking for any password even though it requires sudo permissions?

Edit: by startup, I mean while it's logging the user on, not while booting up the computer

cheesits456
  • 1,282
  • 2
    Can you edit the question to include the script? I am guessing that you have a sudo command in the script. If you remove the sudo commands and call the script from /etc/rc.local, it should run as root at startup. When you call it from the command line, you will need to prefix the script with sudo – Nick Sillito Dec 31 '16 at 07:20
  • there are indeed sudos in the script – cheesits456 Dec 31 '16 at 07:21
  • @NickSillito, Is the /etc/rc.local a default file or folder and does he have to create it ? – George Udosen Dec 31 '16 at 07:32
  • 1
    http://askubuntu.com/a/290100/158442 or http://askubuntu.com/a/713879/158442 – muru Dec 31 '16 at 07:32
  • @NickSillito OP needn't remove the sudos from the script, since the root user, by default, can run sudo without password – muru Dec 31 '16 at 07:34
  • 5
    In that case, see http://askubuntu.com/questions/159007/how-do-i-run-specific-sudo-commands-without-a-password or http://askubuntu.com/q/155791/158442 to see how you can run that script without being prompted for a password. – muru Dec 31 '16 at 09:31
  • First of all, is sudo absolutely necessary in your script ? If not, remove it. Alternatively, find out to which group that command belongs with ls -l /path/to/command/binary. If it's anything other than root , consider adding yourself to that group. Then you will be able to run without need for sudo. That's first. Second, is it absolutely necessary to run when logging-in or can it run when login screen shows up ? There are ways to run scripts as root at login screen itself. – Sergiy Kolodyazhnyy Dec 31 '16 at 09:45
  • @serg yes login screen will work I just thought it was easier to do it during login – cheesits456 Dec 31 '16 at 09:46
  • @ChristianF97 OK , but before I post any answer, tell me this: is the sudo absolutely necessary there ? Whenever you add something to run as root on login screen or elsewhere for that matter, it's a security hole. – Sergiy Kolodyazhnyy Dec 31 '16 at 09:50
  • yes sudo is necessary and I don't care about security here - I have other forms of security that are sufficient for my current usage – cheesits456 Dec 31 '16 at 10:04

1 Answers1

3

Custom scripts that get executed on startup as root can be started via rc.local

You have to include your script in /etc/rc.local as it will be run whenever the user's run level changes, put the script before the last line in /etc/rc.local that contains: exit 0