HowTo: Raspberry start command on startup with tmux

What you want is to automatically start a script or programm when your raspberry pi boots. And you want so specify a user which is executing the process. Even better, you want to start it in a tmux session because this allows you to attach to the session and see whats going on. You are awesome. But you don’t know how to do it ? Simply follow this simple steps:

 

1. Create a bash script file tmux_start.sh (e.g. with: touch tmux_start).

2. Add the following lines to this file (e.g. nano tmux_start.sh):

#!/bin/bash
tmux new-session -d -s peter 'python /home/pi/peter.py'

This command will create a new tmux session called „peter“ and execute the command „python file.py“.
Note: I used the total path.

3. Now we set up the autostart. On the raspberry pi one way is to enter a line in /etc/rc.local. Thats want we wanne do. (so: sudo nano /etc/rc.local) copy and paste this:

sudo -u pi bash /home/pi/tmux_start.sh &

This command will execute a the bash script as user ‚pi‘.

[[{„type“:“media“,“view_mode“:“media_large“,“fid“:“122″,“attributes“:{„alt“:““,“class“:“media-image“,“height“:“167″,“typeof“:“foaf:Image“,“width“:“309″}}]]

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.