XFCE: How to autostart a sudo-script on boot

Hi,
since my switch to Manjaro XFCE this script does not autostart on boot anymore.

rc.local:

#!/bin/bash
#
# /usr/local/sbin/rc.local: Local multi-user startup script.
sudo dell-bios-fan-control 0
sudo modprobe i8k force=1
echo 'ik8' | sudo tee -a /etc/modules
systemctl start i8kmon

then chmod +x the rc.local file

copied to:
/usr/local/sbin/rc.local

reboot

Doesn’t work on XFCE. :confused:

Please can anybody help to find a working solution?

pappl

I would try copying it to /etc/profile.d although… Manjaro has several different ways of autostarting things: https://wiki.archlinux.org/index.php/Autostarting

Hi,

tried several options:

/etc/profile.d/autostart.sh -> Doesn’t work

/home/pappl/.config/autostart/autostart.desktop -> Doesn’t work

Add .sh to to autostart in XFCE settings -> Doesn’t work

:thinking:

It won’t work in xfce startup as it uses sudo.

What about a systemd unit?

[Unit]
Description=Example systemd service.

[Service]
Type=simple
ExecStart=/bin/bash /usr/bin/your-script-here.sh

[Install]
WantedBy=multi-user.target

Take out the sudo commands and move to /usr/bin

2 Likes

:face_with_symbols_over_mouth:, i quit trying.

I stopped trying to start a file script on boot.
Opened XFCE settings -> Session and Startup -> Add -> Command:

sleep 10 && sudo dell-bios-fan-control 0 && sudo modprobe i8k force=1 && sleep 1 && echo 'ik8' | sudo tee -a /etc/modules && systemctl start i8kmon

Reboot -> Doesn’t work.
If i copy/paste it in the terminal it works.

Do these autostart variations support sudo on startup?
EDIT 1: Yes, this doesn’t support sudo

EDIT 2:

Will try now.

Right, been trying to recall how to do this as it has been a few months :smiley:

# Create your.service in:
/etc/systemd/system/yourname.service
 
# Enable it:
sudo systemctl enable yourname.service

reboot
1 Like

It works!
Thanks a lot. :hugs::+1:

Here a summary of required steps:

1. Create and edit a bash-file (.sh) with your terminal commands.
Leave all
sudo , will be done automaticly!
Using nano text editor here:

sudo nano /usr/bin/autostart.sh

Paste this into the created .sh file:

#!/bin/bash
#
# /usr/bin/autostart.sh: Local multi-user startup script.
place your terminal-command 1 here
place your terminal-command 2 here
place your terminal-command 3 here and so on

Edit your commands 1, 2, 3,....

In my case:

#!/bin/bash
#
# /usr/bin/autostart.sh: Local multi-user startup script.
sudo dell-bios-fan-control 0
sudo modprobe i8k force=1
echo 'ik8' | sudo tee -a /etc/modules
systemctl start i8kmon

If you are using nano then save by pressing Ctrl+O -> hit Enter -> Ctrl+X
do a:
chmod +x '/usr/bin/autostart.sh' to set permissions.

2. Create systemd service to run the .sh on boot:
then:
sudo nano '/lib/systemd/system/autostart.service'

Copy/paste the following into the editor:

[Unit]
Description=Example systemd service.

[Service]
Type=simple
ExecStart=/bin/bash /usr/bin/autostart.sh

[Install]
WantedBy=multi-user.target

Press Ctrl+O -> Hit Enter -> Ctrl+X if you are using nano text editor.

3. Now start services and enable to restart on boot:

sudo systemctl start autostart
sudo systemctl status autostart
sudo systemctl enable autostart

reboot, all commands will be executed on boot.

:grinning:

3 Likes

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