Running commands on system boot

I want to run some command at the time of the start of system. I am not sure it is a system setting or is have to related to XFCE. How should I set it up properly? I tried to create .xinitrc and put commands there but nothing happened, not sure if the format was wrong of I should used a different file. What should I do?

Since you are asking specifically in the context of XFCE – usually it’s best or at least easiest to just use the desktop environment’s startup applications if at login is soon enough for you. In this case Session and Startup → Application Autostart → + to add an autostart application.

If at login is not soon enough you need to be careful if your application does in fact require X to be up. Generally there’s systemd user units (although I’m not sure if EndeavourOs has those set up; Manjaro does), cron @reboot, X11 session startup, systemd system unit, /etc/rc.local, …

And yes, whether or not something like ~/.xinitrc works is a bit dependent on specific distribution; would need to verify – but you’re likely as said best of with an XFCE startup application anyway, so…

3 Likes

I think I have seen autostarting application before. It is using .desktop files. But how I can run commands? Like I need to switch a keyboard key by using setxkbmap command. How can I do that?

Just go to the mentioned Session and Startup → Application Autostart → + and add a command; name/description whatever; command /usr/bin/xkbmap ....

Seeing as how xkbmap confirms needing X up this is indeed likely a fine / the best route.

1 Like

Thanks, I had no idea XFCE has a GUI Startup application. That solves the problem somehow but I still prefer a text config file for portability if possible.

I’m afraid that portability would be to say you do not so much want the init file route; this stuff varies quite a bit between distributions and potentially even between e.g. display managers. On plain Arch I believe (but am not going to test) that you want ~/.xprofile but that does not for example work on Debian where you’d go ~/.xsessionrc which does not work on Ubuntu where … who knows/remembers.

I.e., suit your fancy – but I’d stick with the desktop startup application :slight_smile:

1 Like

I understand that, but it is still a bash command I can move or rename from one file to another. I am not planning on hopping distros , but I like to have the settings in files I know their location in case of a failure and need of a fresh install.

Well, try ~/.xprofile. Who knows – maybe you get lucky :slight_smile:

1 Like

Could this be what you are looking for:

https://wiki.archlinux.org/title/Setxkbmap#Using_X_configuration_files

?

2 Likes

I will give a try. I found a example xinitrc file under /etc , but still can’t figure out why it is not working. Like if it is not supporting it why it is there then?

This is actually very helpful, I am going to test it.

What you need is to add a start-up hook to your DM.

For example, if you are using lightdm, you should edit the /etc/lightdm/lightdm.conf and add the path of your script to session-setup-script.

session-setup-script=/path/to/your/script

This will guarantee that your script will be executed after you log in at your greeter.

I know this works because I used this method to run a script that sets up all my monitors.

First, find out which DM you are using. You are using XFCE, so it’s most likely lightdm.

2 Likes

Note; generally speaking xorg.conf (fragments) are not a general answer to X startup applications. In this case your xkbmap might in fact have an alternative in direct configuration through such fragments, but you’d need to translate stuff.

1 Like

Excellent, I am going to test it asap.

Note that you have to put your setxkbmap command into a bash script and make it executable.

#!/usr/bin/bash

#add your commands here

Make it executable chmod +x script.sh

1 Like

At the very least historically/generally ~/.xinitrc and /etc/xinitrc were for the startx route – although then of course when that became the rare situation some distributions – and not all – sourced it/them from their display manager setup as well. And see here why I said to just not pay that junk any mind anymore. This shit has always been one of the worst things about “Linux” and now that the X server is very definitively on its way out one should strive to not learn anything about it anymore… I say.

1 Like

What is “greeter” btw?

I am definitely don’t want to mess with that, as you said X has a lot of issues. But I just spent a lot of time configuring stuff (as a first timer to Linux as my main machine). I just don’t want to spend that much time an effort to set up my main computer ever again.

A greeter is a piece of software that provides a GUI for a user to login rather than the usual TTY interface. Every time you type in your password when you log into your system, you are interacting with a greeter.

You can learn more about greeters and lightdm here: https://wiki.archlinux.org/title/LightDM

1 Like

Welcome to the land of penguins!

1 Like