Rc.local not executing script


I’m trying to run a script on startup, via the file /etc/rc.local

However it doesn’t seem to work.

The contents of that file is as follows:

# /etc/rc.local: Local multi-user startup script.

su - USER_FOO -c /usr/local/bin/test.sh &

The script test.sh is a simple test script that is supposed to launch Galculator:


galculator &

exit 0

Execute commands on startup in Manjaro GNOME

My first though is that when the script runs there will be no X active, so galculator can’t open a display (hence the script will likely be running, just not with the result you’re expecting).


Yes, I considered that as a possibility as well. However I tried putting a sleep command in front of the command (after -c) to wait until Xfce was booted, but that didn’t seem to work either.

Would the same issue occur if I create a cron job using Cronie using the @reboot parameter? Do cron jobs that are executed @reboot also execute before X is started?



I still think it’s a display issue. For example, running a GUI application from a virtual terminal doesn’t work unless you set the DISPLAY variable, so switching to tty1 and running xterm will not work, but DISPLAY=:0 xterm will.


Ah, that makes sense.

I already know how to run scripts at startup via the Xfce startup and session settings, however I wanted to find a universal way to launch scripts at startup in Linux (after the desktop environment has loaded), independently of what Linux distro is used or what desktop environment is used.

Just knowing how to do it in Xfce is not good enough for me. :slight_smile:


Okay I figured it out.

I asked on IRC ##linux if there was a way to run scripts on startup, on any Linux distro and any desktop environment.

To achieve it, one needs to create a launcher (a .desktop file) - and place that file in /etc/xdg/autostart and then in the file properties of the launcher you can make it run a command to run your script. The command should look like this:

sh -c '/usr/local/bin/myscript.sh &'

Myscript.sh needs to be made executable, this can be done in Xfce via the file properties. (allow the file to run as a program)

It’s generally good practice to place regular scripts in /usr/local/bin and sudo scripts in /usr/local/sbin . (scripts made by the user/you)

In this way you can run scripts on startup, on any Linux distro and any desktop environment.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.