I want to start a tmux on boot on a raspberry pi - 2. I have written a session.sh
file and I have places it in ~/bin/
file which is in the home directory. This ~/bin/
is also included in the $PATH
and hence It can be triggered.
The Bash file looks like this:
#!/bin/sh
mySession(){
tmux new-session -d -s SessionName
tmux new-window -d -n 'windowName' "~/bin/myPythonScript.py"
}
mySession
exit 0
I have given execution rights to all scripts including the above mentioned bash script too using chmod +x session.sh
In the rc.local I refer to trigger this file as follows:
#!/bin/sh
scriptSession(){
echo "starting the tmux session"
~/bin/session.sh &
}
scriptSession
exit 0
I have tried rebooting my Pi many times but the session never gets triggered.
when I execute sudo tmux ls
, it just shows error Connecting to Server
however when I do sudo /etc/rc.local
or sudo ~/bin/session.sh
the session starts! I do not want this to happen since I want automatic start on boot not a user triggered session
Any Idea what could be the problem?
Edit
I also tried collecting a fail log in a bash subshell using thing the following in the rc.local file:
(scriptSession)&>>/var/log/myLog.txt
but upon cat /var/log/myLog.txt
nothing shows up and the script still fails
rc.local
there isscriptSession
function defined but never run. Yet you wrote "when I dosudo /etc/rc.local
(...) the session starts". Does it really?