First create an executable script (my-script.sh):
vim /home/christopher/my-script.shAdd the following code:
#!/bin/sh
# my-script.sh
# Make sure to use absolute paths in the scripts
# rather than relative paths.
touch /home/christopher/hello.md
echo "Hello World!" >> /home/christopher/hello.md
exit 0Edit rc.local file:
sudo vim /etc/rc.local
Add new line to execute the script:
#!/bin/sh
/bin/sh /home/christopher/my-script.sh
exit 0If the script includes a loop or it is meant to be executed indefinitely, we might need to add and ampersand at the end of the line:
#!/bin/sh
/bin/sh /home/christopher/my-script.sh &
exit 0Finally, grant executable privileges to /etc/rc.local file and reboot the raspberry pi:
sudo chmod +x /etc/rc.localEnable and check rc-local service
# Enable rc-local service
sudo systemctl enable rc-local.service
# Check status
sudo systemctl status rc-local.servicesudo reboot -h now
