This will show how you can setup scripts that will run on bootup of a Raspberry Pi. Any user in the /home/
directory where the name of the user matches the name of their home directory will be able to take advantage of this setup, as well as the root user.
- Add the following code to the file:
/etc/rc.local
, but be sure to leave the last line of the file asexit 0
# Startup scripts
## Root
if [ -f /root/startup.sh ]; then
bash -e /root/startup.sh &
fi
## Users in /home
for d in /home/*; do
if [ -d ${d} ]; then
if [ -f ${d}/startup.sh ]; then
username="$(basename ${d})"
sudo --user="${username}" bash -e ${d}/startup.sh &
fi
fi
done
unset d
- Create a script in the home folder for each user listed in /home/ with the name
startup.sh
Example startup.sh
script (the hashbang and user execute privileges can be added optionally):
#!/bin/bash
# This startup script is called from /etc/rc.local
echo $(date) > ~/.bootdate
Now when your Pi boots up it will record the date and time in each user's home directory in the .bootdate
file