Run script at startup

Hello again, it’s been a little while since I’ve been here! I’ve upgraded to the Lunar Lobster version, by the way, it definitely feels like an upgrade. Anyway, my dilemma:

In order to turn off several irritating “features” of my old dinky laptop (cpu turboboost for maximum overheating damage, disabling mouse movement while pressing keyboard buttons to make all gaming impossible, etc.) I have to run terminal commands to turn them off. I would very much like to run these on boot or startup, so that I don’t have to constantly copy & paste them every time I turn on the computer. I’ve followed like six or seven tutorials, methods of doing so from elsewhere on the internet, and not a single one of them have worked, at all. Is there a special way of making a script run on startup with Lubuntu? Or better yet, just change some values somewhere so that I don’t even need to run a script?

Unrelated, there’s a few features of Lunar Lobster that I really like, such as the much better multiboot menu, I couldn’t stand the old one. Also, all my screen tearing issues are gone, and Steam was actually able to install with zero issues. Extremely happy with the upgrade.

There are two ways to run a script (or generally a program) at startup,

  • via cron by editing

    • crontab or
    • sudo crontab if elevated permissions are necessary,
  • via autostart if graphics are involved and/or your user environment must be started for the script to work.

You can find many tutorials about crontab via the internet. Ask if you need more details about this method.

If you go via autostart, my answer in the following link might be helpful. (It is about rotating the graphical desktop, but the principles apply also when the script contains other commands.)

If your command is fairly simple, put it on the Exec line in the desktop file, but if there are several commands, make a shellscript and put the name of the shellscript on the Exec line in the desktop file. You should make the shellscript executable (but you would do that already when testing it before putting it into autostart).

3 Likes

In order to help you, you should describe your problem and how you solved it.

Disabling CPU features can often be done in the firmware settings. Did you check every setting in the firmware?

2 Likes

Why thank you :0 ! I’ll try editing crontab, last time I tried it on my old install it didn’t ever want to save the file, so I’ll do some more digging on how to get it to work. Autostart might also be a good idea!
I’m now running into problems where I can’t seem to get turboboost to turn off via terminal— I can only force it by editing the file that the 1/0 is in; even sudo doesn’t work. I may have to research if I’m editing the right file. Normally that would just be a BIOS setting, I realize, but I’ll explain why in my next post.

I’m not sure what you mean by how I solved it, if I solved my problem I wouldn’t be here asking how to solve it :0 unless I’m misunderstanding what you mean.

And as for disabling CPU features, you are 100% correct; turning off turboboost is something that should be done in the BIOS. Unfortunately, this laptop I’m using has a broken battery, and thus completely forgets all the firmware settings whenever it gets unplugged :smiling_face_with_tear: (which is often)

Ok, maybe “solved” is the wrong word. I mean, that you have a manual way of fixing/avoiding your problem.

I guess to workaround your turboboost problem, you are doing something like

echo "1" | sudo tee /sys/devices/cpu/intel_pstate/no_turbo

?

So I am asking you to provide your command line interactions.

Replacing the battery is not possible? And you mean the small battery on the mainboard or the laptop battery?

1 Like

Instead of sudo on command lines in crontab you should use sudo crontab (and no sudo in the commands inside it. Do you need some example or have you found any useful tutorial via the internet?

Anyway, until you tell us what commands you use manually, we can only guess how to solve your problem, so please show all the commands you are running manually in order to make things work.

1 Like

Between then and now, I’ve started using

#! /bin/sh
echo "0" | sudo tee /sys/devices/system/cpu/cpufreq/boost
xinput --set-prop 11 282 0
sudo cpufreq-set -g powersave

to fix most of my problems. I’m annoyed that I forgot what the old command was that was having permission issues, but this new one seems to be working. Well, I don’t actually know for certain if it’s turning off turboboost, as there is no intel_pstate file on my machine, but I just assume it’s working because it doesn’t throw any errors. At this point I’ve just put a shell script on my desktop to run, while I’ve been doing research on how to do it automatically— it’s not been hard to wrap my head around, I’ve just had a lot going on irl.

As for the battery situation— I’m guessing the motherboard battery might be dead? I don’t have a way to find out, since I don’t have the tools with me to do so safely. The actual laptop battery is also very dead. It was that way when I received it, it’s been removed for a long time. Boring irl reasons— I’ve been trying to convince myself that I’ll eventually just get a new laptop before I get a new battery for this old one, but every time I’m close to getting either, something happens to make such a purchase irresponsible.

This is what I suggest:

The two commands with sudo should fit as command lines added via sudo crontab after removing sudo.

The command with xinput should fit via autostart as command of the Exec line in the desktop file.


Please notice that cron has a simple environment, so you should have the whole path of the commands (and use redirection to the file instead of tee, because there is no suitable terminal to receive the output anyway, when the command is run @reboot).

Regarding intel_pstate:
According to the intel_pstate documentation:

intel_pstate is a part of the CPU performance scaling subsystem in the Linux kernel (CPUFreq). It is a scaling driver for the Sandy Bridge and later generations of Intel processors. Note, however, that some of those processors may not be supported.

You can check for example sudo dmesg | grep intel_pstate to see whether it is enabled. Or you can cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver.

Anyway, you can add a cronjob as user root to change the boost and scaling governor values at boot.

Regarding xinput:
I think it is enough to put the xinput command in the file .xsessionrc (echo "xinput --set-prop 11 282 0" >> ~/.xsessionrc).
The more complex way would be to create a handcrafted configuration under /etc/X11/xorg.conf.d/.

1 Like

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