This question already has an answer here:

I've seen people saying use screen.

But when I typed "screen" in the terminal, I got: "Please set a terminal type."

Any idea how I can fix this?

marked as duplicate by Archemar, Gilles shell-script Sep 10 '15 at 22:03

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.

  • What does echo $TERM say on the remote box shell? – yaegashi Sep 10 '15 at 2:03
  • @yaegashi it says "dumb". I want to run bash. How do I set this variable? – henryforever14 Sep 10 '15 at 2:08
  • You can set the variable with TERM=<desired value> as with any other variable, but the real issue here is why it is not getting set automatically according to your terminal type. What type of terminal are you using? – Celada Sep 10 '15 at 2:13
  • @Celada What do you mean by type of terminal? The remote box runs linux. I am not sure about the distribution though. The shell seems to be bash. – henryforever14 Sep 10 '15 at 2:50
  • 1
    What's your local environment and terminal software you are using? It might be gnome-terminal if you are on Linux desktop, or Putty on Windows. Besides that, setting TERM to xterm or linux or vt100 would probably make screen runnable temporarily. – yaegashi Sep 10 '15 at 3:29

To answer your initial question, the most basic way to keep a command running after logging out is to run it with the nohup command.

For example, if I wanted to run a script, and drop it into the background while keeping it running after logging out I would type:

nohup ./myscript &

More information can be found here: https://en.wikipedia.org/wiki/Nohup

Otherwise, as you stated, screen is a good option.

  • Depending on what you want, it may be better to use setsid for this: setsid ./myscript </dev/null >/dev/null 2>&1. That's a bit more similar to what a real daemon process will do. (Tweak the redirections as desired if, for instance, you want to catch output in a logfile.) – Tom Hunt Sep 10 '15 at 15:11
  • Thanks for information on Nohup. But unfortunately, I don't have root access to the remote box and it seems that nohup is not available, i.e., I get "bash: nohup: command not found". – henryforever14 Sep 10 '15 at 15:43


If you want to run screen , these are the way :
Login to your user :
-- To create a new session for screen
screen -S screenname
-- To detach from the screen 
Ctl + ad
-- To reconnect to screen :
screen -dr screenname
-- To check the current open screens :
screen -ls
-- While in screen , you can use 
   Ctl + ac (to create new screenwindows)
   Ctl + an (move to next screenwindow)
   Ctl + ap (move to previous screenwindow)


You can run a script like this :
/fullpath/to/script/scriptname.sh >> /fullpath/to/log/logname.log 2>&1 
Ctl + z
bg %1 (run in background)
disown %1   
-- To check if its running :
ps -ef | grep scriptname.sh

Note : Ctl here means control key

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