You are not logged in.

#1 2023-12-09 03:00:45

Registered: 2023-12-02
Posts: 4

How can I run a bash script as root via an autostart file?

I made a nice little script that alters my lock screen and desktop wallpaper from time to time, plus some related configuration in one of my apps to give it a more unified look. I've tested it pretty thoroughly so I know the code's doing what it should do - at least using sudo in the terminal (which defeats the whole point of writing the script in the first place). For reference, I'm using Openbox with nitrogen and have tried these steps already:

- Moved script to /usr/local/bin so it's in $PATH
- Made the thing executable (sudo chmod u+x /usr/local/bin/
- Added these lines to Openbox's autostart file
        pkexec &
        nitrogen --restore &
- Restarted PC

Annoyingly, this isn't working (the desktop wallpaper reverted to the previous one and neither of the other things changed). I tried some troubleshooting steps like running sudo so I at least know the thing's in $PATH, but most of the information I've found online regarding my current dilemma is contradictory or outdated so I'm not quite sure what to do here.


#2 2023-12-09 03:34:51

From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,989

Re: How can I run a bash script as root via an autostart file?

Do these modify the user session? If so why does it need to be run with elevated permission?
Would starting it as a systemd service work?  (Hence the question about changing the user session)

Can you share your script?

Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
How to Ask Questions the Smart Way


#3 2023-12-09 11:54:07

From: London
Registered: 2014-02-20
Posts: 7,812

Re: How can I run a bash script as root via an autostart file?

In the highly unlikely event that changing the lock screen & wallpaper needs root permissions you will need a graphical polkit authentication agent running to ask for the password. … ion_agents

Destruam et ædificabo


#4 2023-12-09 16:50:08

Registered: 2012-09-03
Posts: 54,214

Re: How can I run a bash script as root via an autostart file?

You'll also have to make sure the proper display and xauth (or wayland, perhaps dbus) environment is imported.

stat /usr/local/bin/ # w/ the move/chmod you might have caused root:users/744
cat /usr/local/bin/


Board footer

Powered by FluxBB