7

First post here. Please be gentle

There's a way to execute a bash command during the startup of Linux operating system? I could always put the script in /usr/local/bin open the terminal and recall it, but is a little bit annoying.

EDIT1 as suggested by steeldriver: The script has to enter in a root folder and change 2 values of charge thresold contained in a text file. For each start-up I'd like to be sure that the battery level wouldn't go over the 80%.

So in order to do that the script would execute a:

  • cd command
  • sed -i 's/0 100/0 80/g'

all of this, I think, has to be in sudo mode

EDIT2: as asked by K7AAY user:

Ubuntu Desktop 18.04 LTS version, I'm not using any virtualization.


Thanks for the answers

3
  • 3
    Yes there is - but the right way to do it depends on what the command does and what you mean by "startup of Linux operating system" - please edit you question with details. – steeldriver Mar 2 '20 at 12:53
  • You can create a systemd service to run your shell script at boot. An example is implemented in the last part of this answer – Raffa Mar 2 '20 at 15:07
  • To start with, which version of Linux have you installed (Ubuntu server, Ubuntu desktop, Kubuntu, Lubuntu, Xubuntu, Ubuntu MATE, et al.) , and which release number? Are you using virtualization, and if so, which package? Please click edit and add that vital information to your question so all the facts we need are in the question. Please do not use Add Comment. – K7AAY Mar 2 '20 at 17:18
7

You could use crontab -e

@reboot /usr/local/bin/yourscript

You could also copy your *.desktop applications into ~/.config/autostart/ or scripts into ~/.config/autostart-scripts/ directory. But, instead of copying, use ln -s pathtoscript ~/.config/autostart-scripts/

You could also use the next GUI for it if you use KDE Plasma:

enter image description here

Or, for Unity:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.