Run command at startup, Fedora 25

I just reinstalled my laptop and wanted to try gnome 3 (was using ubuntu mate) and figured I could try Fedora as well. Got some few annoyances but figured them out. Now I only have the BIG problem left. Trackpoint speed.
I need to run two commands every time i start:
echo 225 | sudo tee /sys/devices/platform/i8042/serio1/serio2/sensitivity
echo 225 | sudo tee /sys/devices/platform/i8042/serio1/serio2/speed
The problem is that my knowledge is now running out. I tried rc.local, script at init.d, script outside init.d, startup manager but nothing works (the commands do work if I do them manually in the terminal) but no automatic thing so far.
My google skill has also failed so now it is time to give in and ask you guys that probably know a lot more.
Any idea what to do?

2 Likes

did you place the scripts in /etc/init.d ? Did you make them executable?
Do that using chmod +x /etc/init.d/SCRIPTNAME.sh

There are other ways to do this too with like using crontab -e or with systemd

crontab -e

@reboot command

4 Likes

Fedora 25 uses systemd for its init system. Just need to create a systemd service file to run it at boot.

create a file with the extension .service at /etc/systemd/system/ and put the following into it. I will refer to this file as startup.service

[Unit]
Description=Description of the systemd service
After=multi-user.target

[Service]
ExecStart=/Path/to/shell/script.sh

[Install]
WantedBy=default.target

now just run these next 2 commands

sudo systemctl enable startup.service
sudo systemctl start startup.service

first command will tell systemd to run it at boot and the second will start the service.


couple of notes. the systemd service will run the script as root so make sure the service file and the shell script are owned and grouped by root with world only being able to read and execute.

Let me know if you have any problems

7 Likes

Yes. Do the script have to took and be structured in a certain way. I did everything except the last thing (crontab)

I can try that when I get home. I did something similar but the script was different.

Where do I put my commands then? is it in script.sh or
ExecStart = "my Command" (one of the echo above)

i would recommend a script. Your really not supposed to run commands directly plus will be much less hassle to change in the future

Now the startup.service looks like this.

    [Unit]
    Description=Run prackpoint script
    After=multi-user.target

    [Service]
    ExecStart=/etc/Trackpoint.sh

    [Install]
    WantedBy=default.target

Trackpoint.sh looks like this:

#!/bin/bas
echo 225 | sudo tee /sys/devices/platform/i8042/serio1/serio2/sensitivity
echo 225 | sudo tee /sys/devices/platform/i8042/serio1/serio2/speed

But I get this:

[infigo@localhost system]$ sudo systemctl enable startup.service
Failed to enable unit: Invalid argument

what is the output of "ls -la /etc/systemd/system/"

@infigo

You could put the commands in .bash_profile in your home folder. Commands there are run upon logging in.

This:

try this

"sudo systemctl enable /etc/systemd/system/startup.service"

nope.
"Failed to enable unit: Invalid argument"
Again

try removing the "After=" part

then I get:
Failed to enable unit: Invalid argument
Wait...

On the service file add the option User= and (if needed) Group= with the user and group if needed, add it under the [Service] section.

Since your trying to use sudo in the script it sounds like you want it to run as root. You can remove sudo from the script.

you can use journalctl or systemctl status [service] to see more info on whats up with it.

Is your bash script exactly what it is? If so, your first line needs fixed, /bin/bash not /bin/bas

3 Likes

Well the h was missed. Good call but it is still not working.
No errors at least anymore and when i run -la on systemd/system startup.service does show up now

cat /sys/devices/platform/i8042/serio1/serio2/speed will comfirm it took.

nope it is on 97.
But if I run the command manually and it goes to 225 as I want it