9

I need to run a simple batch of commands after the computer boots, something like

sudo thing
sudo thing1 -p

But for the life of me I can't figure out how. I googled and googled and I kept finding the same thing: Place the commands into a /etc/rc.local or /etc/init.d/rc.local file. The problem is that none of those files exist on my system! Furthermore, I have read that /etc/rc.local is deprecated anyway, so what the correct and simple way to do this?

I would like to know how to these two things:

  • run a command after the computer boots

  • run a command after specified user logs in, and run it as the given user

    (And make all that happen solely by editing stuff in the terminal, no GUI tools)

Thank you.

4
  • Possible duplicate of askubuntu.com/questions/1528/bashrc-or-bash-profile. You have five places you can add commands, you pick the best choice for your need... (See also askubuntu.com/questions/121413/… but there may be better too)
    – guiverc
    May 29, 2018 at 7:05
  • 2
    To run commands as root I’d use root’s cron (sudo crontab -e) with the @reboot keyword as explained in this answer, to run a command when a user logs in there the ~/.profile approach as explained here.
    – dessert
    May 29, 2018 at 7:14
  • 3
    Looks like admins do not know meaning of start-up and confusing it with user login. Could anyone please answer this? I do not see point in using crontab over enabling rc-local unit and creating rc.local.
    – wick
    Oct 5, 2019 at 17:36
  • 1
    @wick: mods on StackExchange sites, paradoxically, aren't required to know much about the topic of the question. They simply have mod powers, and sometimes make bad decisions because they don't understand the technical nature of the question. Oct 24, 2019 at 9:14

0

Browse other questions tagged .