0

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

marked as duplicate by Zanna, Jacob Vlijm, Eric Carvalho, user.dz, David Foerster Dec 31 '16 at 15:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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 7:20
  • there are indeed sudos in the script – cheesits456 Dec 31 '16 at 7: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 7:32
  • 1
  • 5
    In that case, see askubuntu.com/questions/159007/… or askubuntu.com/q/155791/158442 to see how you can run that script without being prompted for a password. – muru Dec 31 '16 at 9:31
2

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.