2

This question already has an answer here:

I added the following to /etc/rc.local

(
    cd /home/pi/Desktop
    exec ./start_picoin.sh
) &

The script it executes is nothing more then a simple echo at the moment. I would like this script to be executed in a terminal that stays open after execution. How can I do that?

marked as duplicate by Jacobm001 May 1 '17 at 15:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

You could use a very nice tool called tmux. I use it everyday and what it basically does is gives the end user to run multiple scripts in detached mode (background), however a user can log in to the Detached Session whenever s/he wants at any given time.

  • You can install it via:

    sudo apt update
    sudo apt install tmux
    
  • In your case you could write a the tmux trigger on boot into your rc.local file as follows:

    ## YOUR rc.local file
    #!/bin/sh -e
    
    # always good and safe to use the complete path
    /usr/bin/tmux new-session -d -s mySession
    
    # This statement is a life-saver, if ever your code crashes
    /usr/bin/tmux set-option -t mySession set-remain-on-exit on
    
    # Create a window where you wish to run a code
    /usr/bin/tmux new-window -d -n 'my work' -t mySession:1 'cd /home/pi/Desktop; exec ./start_picoin.sh'
    
     exit 0
    
  • Now since your /etc/rc.local file is triggered on boot under sudo rights, the next time you boot you can see your session mySession by typing:

    sudo tmux ls
    
  • Once you see the session has begun, all you have to do is attach the background session using:

    sudo tmux a
    
  • You will see an empty bash shell, in order to navigate to your running code press Ctrl + B+1

  • Once you see your code running well and want to leave the code running in the background you can simply click: Ctrl + B+D to detach it.

  • If you want to close the complete session you can just type:

    sudo tmux kill-session
    
1

http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs-gui

I am assuming you are using GUI rather than command line? Follow that guide above to launch lxterminal on start up. If you have a script called BootScript.sh in the /home/pi directory then in your autostart file you want to add:

@lxterminal -e "/home/pi/BootScript.sh"

your script will read something like this:

#!/bin/bash

echo Hello World!

$SHELL

The $SHELL part at the ends stops the terminal screen from closing. Make sure you give your script execution privileges using:

chmod -755 /home/pi/BootScript.sh
-1

This is not simple because Raspbian will not give you terminal on boot logged in by default.

First, you need to edit /etc/inittab to enable auto login in your preferred console.

Then I would suggest to add your script to ~/.bashrc and it will execute on login.

EDIT

I've just realized that you asked something else:

Answer is to use nohup before your call.

So, it would be nohup myscript.sh & and it will run after you logout.

Not the answer you're looking for? Browse other questions tagged or ask your own question.