Skip to content

Instantly share code, notes, and snippets.

@connorjan
Last active April 12, 2017 15:23
Show Gist options
  • Save connorjan/9bd857913177455be6cf89667edeea6b to your computer and use it in GitHub Desktop.
Save connorjan/9bd857913177455be6cf89667edeea6b to your computer and use it in GitHub Desktop.
Guide to setting up automatic boot scripts for multiple users on a Raspberry Pi

Raspberry Pi Multi-User Boot Script Setup

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.

  1. Add the following code to the file: /etc/rc.local, but be sure to leave the last line of the file as exit 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
  1. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment