KDE script autorun

Hello i have a script for setting nvidia gpu power limits and clocks

 #!/bin/bash
#Enable persistence mode
sudo nvidia-smi -pm ENABLED
#Set power limit to 140Watts
sudo nvidia-smi -pl 140
#Set clocks
sudo nvidia-smi -lgc 240,1807
#Set target temp to 73c
sudo nvidia-smi -gtt 73

I was wondering if i could make this script autorun and not prompt me for a password on launch

Thanks!

Create a systemd service. There are loads of tutorials out there.

If you could link me a good one that would be great but its fine if you cant thanks!

Asking my :robot: friend:

Could you please generate a list of tutorials for how to make a systemd service?

Sure! Here is a list of tutorials that explain how to create a systemd service:

:speech_balloon:
:robot:

For more: https://wiki.archlinux.org/title/Systemd#

:warning:
Please make some research on your own and if anything is unclear ask the forum.

Good luck!

2 Likes

Yikes, that did not turn out so well–all of those links are 404, except the last one which is not related to making a systemd service at all.

Here are some articles related to creating a systemd service which have not been hallucinated by a chat bot:

An example of creating a service for running your script would be like this:

Create a service file with an editor, for example Nano:

sudo nano /etc/systemd/system/gpu-settings.service

Set up a service which will run your script for you. I have not tested this but perhaps it will be a good starting point:

[Unit]
Description=NVIDIA GPU Settings
Wants=graphical.target
After=graphical.target

[Service]
Type=oneshot
ExecStart=/path/to/your/script.sh

[Install]
WantedBy=graphical.target

Systemd sometimes has problems with files stored in the user’s home directory, so if needed you should move your script somewhere else like /usr/local/bin.

Start and enable the service:

sudo systemctl enable --now gpu-settings.service

Then reboot and see if it works. If not, you can try changing the dependency directives or the target, or examine the journal to see why it is failing (systemctl status gpu-settings.service).

4 Likes

1477bf03933b90a030e469901e5efa97-1326238874

Seems I asked the wrong friend :blush:

1 Like

:smiley: Apologies, I use:
https://www.linode.com/docs/guides/start-service-at-boot/

3 Likes

Throws up this error when i try to execute from home directory or /usr/local/bin

gpu-settings.service: Failed to execute /usr/local/bin/nvidia-settings.service: Failed to execute /usr/local/bin/nvidia-pl.sh: Exec format error

Nevermind was able to solve it by changing line: 8 from

ExecStart=/usr/local/bin/nvidia-pl.sh

To

ExecStart=/bin/bash /usr/local/bin/nvidia-pl.sh
1 Like

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