Main menu

Start a program at boot up

I have no keyboard and display connected to my Raspberry Pi (running Raspbian), but log in to it over the network by using ssh.

Now, I wanted to automatically start a program when the Raspberry Pi boots up, but also be able to see the console output of that program when needed.

To accomplish that, I’ve done the following:

sudo apt-get install mingetty

sudo apt-get install screen

Edit /etc/inittab, and changed the part with getty’s to autologin on tty3 with mingetty as user pi

...snip...
# /sbin/getty invocations for the runlevels.
#
# The "id" field MUST be the same as the last
# characters of the device (after "tty").
#
# Format:
# :::
#
# Note that on most Debian systems tty7 is used by the X Window System,
# so if you want to add more getty's go ahead but skip tty7 if you run X.
#
1:2345:respawn:/sbin/getty --noclear 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
#3:23:respawn:/sbin/getty 38400 tty3
#4:23:respawn:/sbin/getty 38400 tty4
#5:23:respawn:/sbin/getty 38400 tty5
#6:23:respawn:/sbin/getty 38400 tty6
T:23:respawn:/sbin/mingetty --autologin=pi tty3
...snip...

Add the following to /home/pi/.profile, to autostart a program when user pi login on tty3

So, when the Raspberry Pi boots, user pi will automatically log in and run the program tstat. Because tstat is started with screen, I can log in with ssh and run screen -R to see the output of tstat and press ctrl-a d to exit screen, but leave tstat running.