You are not logged in.

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

Archwing
Member
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/script.sh)
- Added these lines to Openbox's autostart file
        pkexec seasons.sh &
        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 script.sh 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.

Offline

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

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,804

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

Offline

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

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,732
Website

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.

https://wiki.archlinux.org/title/Polkit … ion_agents

Offline

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

seth
Member
Registered: 2012-09-03
Posts: 51,653

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/seasons.sh # w/ the move/chmod you might have caused root:users/744
cat /usr/local/bin/seasons.sh

Offline

Board footer

Powered by FluxBB