Raspberry Pi Tips

Automatically launching application

Raspberry Pi 3 Model B V1.2

  $ cat /etc/debian_version
  9.11

For launching shell script automatically, I tried several options to launch application on starting Raspberry Pi.

As my service of "potone.sh" is assumed to interaction on pressing key on LXDE terminal (like stop image screen by 'Esc', stop receiver therad by 'f' key etc., I found that write script at $HOME/.config/autostart/*.desctop was the easiest for me to do what I want.


Option1: ~/.config/autostart/*.desktop

This opens terminal on starting RaspPi and execute command on that.

  $ vi ~/.config/autostart/potone.desktop
  /home/pi/repo/tatoflam/potone/potone.sh

Option2: ~/.config/lxsession/LXDE-pi/autostart

This execute GUI applications on starting RapPi. As this cannot open a terminal and execute command in it, this did not work for my case.

  $ mkdir -p ~/.config/lxsession/LXDE-pi
  $ cp /etc/xdg/lxsession/LXDE-pi/autostart ~/.config/lxsession/LXDE-pi/
  $ vi ~/.config/lxsession/LXDE-pi/autostart
  /home/pi/repo/tatoflam/potone/potone.sh > /home/pi/repo/tatoflam/potone/log/potone.log 2>&1

Option3: Write crontab (@reboot)

This executes commandline by a specific user on starting RaspPi. This causes error that program cannot open GUI window. This did not work for my case.

  $ crontab -e
  @reboot    /home/pi/repo/tatoflam/potone/potone.sh > /home/pi/repo/tatoflam/potone/log/potone.log 2>&1

Ref: