Run Terminal Command at Boot
From: https://superuser.com/questions/471253/ubuntu-how-to-run-a -terminal-command-on-boot





Ubuntu - How to run a terminal command 
on boot?
I want to execute a command when Ubuntu boots. The commands in particular are:
	sudo shutdown +m
sudo shutdown +1

I want the computer to shut down as soon as it starts for testing purposes.
I plan on switching the computer back on with a bit of circuitry I am
testing.

How can I execute this command automatically at system start up?

12 "auto shutdown at boot" sounds evil. :) – 
    Ankit Sep 7, 2012 at 13:00



Answer 14 Place it in /etc/rc.local. (It is run as root, so sudo is not needed there.) Also, you may be interested to read additional info about runlevels: http://en.wikipedia.org/wiki/Runlevel u1686_grawity 430k6464 gold badges899899 silver badges973973 bronze badges Comments You can also go to System/Preferences/Startup Applications, and add the script there. – SaintWacko Sep 7, 2012 at 13:06 Not working for me on Ubuntu Server 18.04 - I want to swap on as sudo swapon /swapfile – Nam G VU Feb 25, 2020 at 11:54 Use crontab with @reboot syntax working for me ref. superuser.com/a/586078/34893 – Nam G VU Feb 25, 2020 at 12:12
Answer 5 There are different ways to automatically run commands: Ankit 4,72622 gold badges2323 silver badges3232 bronze badges
Answer 1 For simple things you can add a command in System->Preferences->Sessions pointing to the location of your script. Alternatively you can add it to /etc/init.d/rc.local or make an upstart job if it's a more low level stuff. Take a look at https://help.ubuntu.com/community/UbuntuBootupHowto for more info