Linux

Tutorial To Auto Execute Linux Scripts And Commands During Startup

Tutorial To Auto Execute Linux Scripts And Commands During Startup
Written by itsubuntu

Tutorial To Auto Execute Linux Scripts And Commands During Startup

In this tutorial post, we are going to talk on the methods to execute scripts/commands and applications automatically on startup. There are number of methods from where you can easily configure the auto-execution of the Linux startup scripts and command.

Tutorial To Auto Execute Linux Scripts And Commands During Startup

Method 1:

Use

Use The /rc.local To Auto Execute Linux Scripts And Commands During Startup

Run the command below on the Terminal.

sudo nano /etc/rc.local

It will open the rc.local file on the nano editor or it would create a new one. Now you need to enter your commands between the #! /bin/bash and exit 0 lines

//path-to-your-bash-script
exit 0

Now you should make the /rc.local file executable. Run the command below for this.

sudo chmod +x /etc/rc.local

Method 2:

Use Systemd To Auto Execute Linux Scripts And Commands During Startup

We can use the Systemd to automate Linux scripts and commands on startup. To get started, run the commands below:

mkdir -p ~/.config/systemd/user
nano ~/.config/systemd/user/update-notifier.service

After execution of the above commands, the nano editor will open, paste the commands below here.

[unit]
Description=Reminder to Update System
PartOf=graphical-session-target

[Service]
ExecStart=bash -c 'sleep 50; notify-send "Please, Update your System Now"
Type=oneshot

[Install]
WantedBy=graphical-session.target

Run the commands below to make it executable.

chmod 644 ~/.config/systemd/user/update-notifier.service
systemctl --user enable update-notifier.service
systemctl --user daemon-reload
reboot

You can also use the Startup Application GUI app in your Ubuntu to configure the Startup scripts or commands. You can use this tool to Auto Execute Linux Scripts And Commands During Startup.

About the author

itsubuntu

Leave a Comment