Run command while booting
Run command while booting
Categories:
Run specific command while booting
You can write any command that you want to execute while booting in the /etc/rc.local
file.
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Auto boot
bash /home/ubuntu/scripts/boot.sh > /dev/null 2>&1
# Auto deploy
bash /home/ubuntu/scripts/deploy.sh > /dev/null 2>&1
You can run the following command to check this service status
systemctl status rc.local.service
$ systemctl status rc.local.service
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; enabled-runtime; vendor preset: enabled)
Drop-In: /lib/systemd/system/rc-local.service.d
└─debian.conf
Active: active (exited) since Wed 2019-09-25 15:52:07 CST; 33min ago
Docs: man:systemd-rc-local-generator(8)
Process: 793 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
Sep 25 15:54:33 ip-172-31-25-154 rc.local[793]: Deploy Done
Using crontab to run your command after booting
crontab -e
# Auto boot
@reboot bash /home/ubuntu/scripts/boot.sh > /dev/null 2>&1
# Auto deploy
@reboot bash /home/ubuntu/scripts/deploy.sh > /dev/null 2>&1
Reference
- boot - Run bash script on startup - Raspberry Pi Stack Exchange
- Schedule Tasks on Linux Using Crontab | kvz.io