NSLU2-Linux
view · edit · print · history

HowTo.KeepRemoteConsoleSessionRunning History

Hide minor edits - Show changes to markup

June 13, 2008, at 06:44 PM by MarkStinson -- dtach src updated Jan 30, 2008 (0.8) - last update 2004 (0.7)
Changed lines 135-136 from:
to:
  • UPDATE: dtach has now reached 0.8 Jan 30, 2008.
May 06, 2008, at 04:24 PM by BrianZhou -- formatting
Changed lines 246-250 from:

1. ssh to the slug as per normal. 2. $ ftp ftp.desired.server.org 3. Navigate to the desired area and get or mget the file(s) you want, this will start the download. 4. Type <CTRL>z 5. It should say something like:

to:
  1. . ssh to the slug as per normal.
  2. . $ ftp ftp.desired.server.org
  3. . Navigate to the desired area and get or mget the file(s) you want, this will start the download.
  4. . Type <CTRL>z
  5. . It should say something like:
Changed lines 252-253 from:

6. $ bg 1 - this starts the process in the background 7. It should say something like:

to:
  1. . Starts the process in the background $ bg 1
  2. . It should say something like:
Changed lines 256-258 from:

8. Type ls -al a few times to ensure that the file you are downloading is getting bigger over time. If it is, it's working! 9. Exit your ssh session. If you like, you can ssh back in again to try step 8. just to ensure that it's working.

to:
  1. . Type ls -al a few times to ensure that the file you are downloading is getting bigger over time. If it is, it's working!
  2. . Exit your ssh session. If you like, you can ssh back in again to try step 8. just to ensure that it's working.
April 25, 2008, at 10:54 PM by Fred -- A tip to quickly and easily running ftp in the background.
Added lines 241-265:

In the bit where it says:

  • Learn to use your shell's job control such as `fg`, `bg` and & ( read your shell's manpage and check your docs )

I'd like to share how I use the slug to download large files via ftp so that I don't have to have my main computer on.

1. ssh to the slug as per normal. 2. $ ftp ftp.desired.server.org 3. Navigate to the desired area and get or mget the file(s) you want, this will start the download. 4. Type <CTRL>z 5. It should say something like:

              [1]+  Stopped                 ftp ftp.desired.server.org

6. $ bg 1 - this starts the process in the background 7. It should say something like:

              [1]+ ftp ftp.desired.server.org &

8. Type ls -al a few times to ensure that the file you are downloading is getting bigger over time. If it is, it's working! 9. Exit your ssh session. If you like, you can ssh back in again to try step 8. just to ensure that it's working.

If you need to kill the ftp process for whatever reason, list all processes via: ps -ax If the ftp is running and shouldn't be, killall ftp or if it's not responding, killall -9 ftp

February 24, 2008, at 11:15 AM by bla --
Changed lines 218-219 from:
  • Ctrl-A followed by [Esc] then you can scroll up and down the virtual screen without scrollbars and even select and copy text. Press [Esc] again and you are back to where your cursor is.
to:
  • You don't need scollbars. Press Ctrl-A followed by [Esc] then you can scroll up and down the virtual screen with the cursor keys and you can even select and copy text. Press [Esc] again and you are back to where your cursor was.
February 24, 2008, at 11:13 AM by bla --
Changed lines 218-219 from:
to:
  • Ctrl-A followed by [Esc] then you can scroll up and down the virtual screen without scrollbars and even select and copy text. Press [Esc] again and you are back to where your cursor is.
January 27, 2008, at 11:16 AM by asdf -- moved \"-z\" in the dtach command lines, as the socket path has to immediately follow \"-A\"
Changed lines 92-93 from:
  dtach -A -z /tmp/mydtachsocket bash
to:
  dtach -A /tmp/mydtachsocket -z bash
Changed line 100 from:
  1. dtach -A -z /tmp/myvisession vi log-or-filename
to:
  1. dtach -A /tmp/myvisession -z vi log-or-filename
Changed lines 106-107 from:

You can try it out on from a couple of terminals on the same workstation without having to change permission, it's freaky cool. Just dtach -A -z /tmp/mydtachsocket bash in multiple consoles.

to:

You can try it out on from a couple of terminals on the same workstation without having to change permission, it's freaky cool. Just dtach -A /tmp/mydtachsocket -z bash in multiple consoles.

Changed lines 110-111 from:
  dtach -c -z /tmp/bgdtach myscript
to:
  dtach -c /tmp/bgdtach -z myscript
November 17, 2007, at 05:15 PM by BrianZhou -- bash disown
Changed line 2 from:
  • nohup and standard job control
to:
  • nohup, disown and standard job control
Added lines 30-39:

bash disown

$ help disown
disown: disown [-h] [-ar] [jobspec ...]
    By default, removes each JOBSPEC argument from the table of active jobs.
    If the -h option is given, the job is not removed from the table, but is
    marked so that SIGHUP is not sent to the job if the shell receives a
    SIGHUP.  The -a option, when JOBSPEC is not supplied, means to remove all
    jobs from the job table; the -r option means to remove only running jobs.
November 05, 2007, at 04:34 PM by MarkStinson -- added article link on modifying screen status
Added lines 244-245:
  • http://www.debian-administration.org/articles/560 - Easy intro into formatting the Screen status line.
September 26, 2007, at 04:22 AM by markstinson -- cleaned up a typo, unescaped slash, and moved user example in to main screen section
Changed lines 84-85 from:

Then to detach from your session you could just close your terminal application or you can press the default Ctrl+

to:

Then to detach from your session you could just close your terminal application or you can press the default Ctrl+\ .

Added lines 189-201:

Example one - Create a detached screen session. Then attach to it later (from User Contributions)

The following screen command will create a new screen session:

screen -dmS midnight mc
  • '-d -m' means: start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts, so you can use this in /etc/rc.local to run anything in the background;
  • '-S midnight' means: sets the screen-name to 'midnight', so if you're running multiple screens you can easily find and re-attach to it, instead of guessing the screen number;
  • 'mc' tell screen to start the command 'mc' (midnight commander, if you've installed it).

To attach to this screen, enter: screen -R midnight

Deleted line 243:
Deleted lines 245-253:
  • The following screen command will create a new screen session:
screen -dmS midnight mc
  • '-d -m' means: start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts, so you can use this in /etc/rc.local to run anything in the background;
  • '-S midnight' means: sets the screen-name to 'midnight', so if you're running multiple screens you can easily find and re-attacht to it, instead of guessing the screen number;
  • 'mc' tell screen to start the command 'mc' (midnight commander, if you've installed it).
To attach to this screen, enter: screen -R midnight
September 22, 2007, at 01:05 AM by fcarolo -- formatting
Changed lines 229-231 from:
screen -AadR
to:
screen -AadR
Changed lines 234-237 from:
  • The following screen command will create a new screen session
to:
  • The following screen command will create a new screen session:
screen -dmS midnight mc
Changed lines 242-244 from:
screen -dmS midnight mc

To attach to this screen, enter: screen -R midnight

to:
To attach to this screen, enter: screen -R midnight
September 22, 2007, at 01:04 AM by fcarolo -- formatting
Changed lines 229-231 from:
 screen -AadR
to:
screen -AadR
Changed lines 239-240 from:
 screen -dmS midnight mc
to:
screen -dmS midnight mc
September 22, 2007, at 01:03 AM by fcarolo -- formatting
Changed lines 15-16 from:

The nohup binary is normally included with even the most minimal unix like systems. With optware, slugos or debian, it's part of the coreutils package.

to:

The nohup binary is normally included with even the most minimal unix like systems. With Optware, SlugOS or Debian, it's part of the coreutils package.

Changed lines 234-239 from:
  • The following screen command will create a new screen session,

'-d -m' means: start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts. (So you can use this in /etc/rc.local to run anything in the background) '-S midnight' means: sets the screen-name to 'midnight' (so if you're running multiple screens you can easily find and re-attacht to it, instead of guessing the screen number); 'mc' tell screen to start the command 'mc' (midnight commander, if you've installed it).

to:
  • The following screen command will create a new screen session
    • '-d -m' means: start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts, so you can use this in /etc/rc.local to run anything in the background;
    • '-S midnight' means: sets the screen-name to 'midnight', so if you're running multiple screens you can easily find and re-attacht to it, instead of guessing the screen number;
    • 'mc' tell screen to start the command 'mc' (midnight commander, if you've installed it).
Changed line 241 from:

To attach to this screen, enter: screen -R midnight

to:

To attach to this screen, enter: screen -R midnight

September 20, 2007, at 11:01 AM by cbase --
Changed lines 153-154 from:

And, what's probably more important: I've noticed screen slurping up a lot of memmory (up to 1MB if I've read the numbers correct), and because you'll be running a sh or bash inside it, that takes _another_ 400-500K for every window inside screen.. Be aware of this if you're planning to use this on small-memmory devices like the NSLU2.

to:

What's probably more important: I've noticed screen slurping up a lot of memmory (up to 1MB if I've read the numbers correct), and because you'll be running a sh or bash inside it, that takes _another_ 400-500K for every window inside screen.. Be aware of this if you're planning to use this on small-memmory devices like the NSLU2.

Changed lines 170-172 from:

Someone feel free to point to an article on how to build it. For Debian users, as root: apt-get install screen

to:

Someone feel free to point to an article on how to build it from source.

September 20, 2007, at 10:57 AM by cbase -- screen example
Changed line 237 from:

'-S midnight' means: sets the screen-name to 'midnight' (so if you're running multiple screens you can easily find and re-attacht to it);

to:

'-S midnight' means: sets the screen-name to 'midnight' (so if you're running multiple screens you can easily find and re-attacht to it, instead of guessing the screen number);

Changed line 242 from:

To attach to this screen, ener: screen -R midnight

to:

To attach to this screen, enter: screen -R midnight

September 20, 2007, at 10:55 AM by cbase -- screen memmory usage and screen run-in-background example
Changed lines 152-153 from:

Unfortunately, you may end up with a hand cramp if you're managing several screen screens/tab at a time. Everything is Ctrl+Key CommandKey combo sequence.

to:

Unfortunately, you may end up with a hand cramp if you're managing several screen screens/tab at a time. Everything is Ctrl+Key CommandKey combo sequence. And, what's probably more important: I've noticed screen slurping up a lot of memmory (up to 1MB if I've read the numbers correct), and because you'll be running a sh or bash inside it, that takes _another_ 400-500K for every window inside screen.. Be aware of this if you're planning to use this on small-memmory devices like the NSLU2.

Changed lines 170-171 from:
to:

For Debian users, as root: apt-get install screen

Added lines 176-182:

It will start screen, load a shell and drop you into it. You can exit it by exiting the shell (just type 'exit', and screen will close too). You can detach it by pressing Ctrl+A D You'll be returned to the non-screened shell, and the process running in screen will continue running in the background.

To re-attach to a screen session, enter: screen -R You'll return to your screen session jus where you left it. (however, if there's more than one screen running then it will give you a list of screens to attach to)

Inside the 'screen', there are various commands you can use:

Added lines 233-242:
  • The following screen command will create a new screen session,

'-d -m' means: start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts. (So you can use this in /etc/rc.local to run anything in the background) '-S midnight' means: sets the screen-name to 'midnight' (so if you're running multiple screens you can easily find and re-attacht to it); 'mc' tell screen to start the command 'mc' (midnight commander, if you've installed it).

 screen -dmS midnight mc

To attach to this screen, ener: screen -R midnight

September 19, 2007, at 03:14 PM by BrianZhou -- formatting
Changed lines 220-222 from:
 screen -AadR?
to:
 screen -AadR
September 19, 2007, at 03:13 PM by BrianZhou -- screen -AadR
Added lines 198-199:

Changed lines 219-222 from:
to:
  • The following screen command will create a new session if none exists, detach a session if remotely attached, and (re)attach to it.
 screen -AadR?
September 19, 2007, at 03:10 PM by BrianZhou -- added horizontal bars
Added line 6:

Added line 36:

Added lines 143-144:

September 19, 2007, at 03:08 PM by BrianZhou -- nohup part of coreutils
Changed lines 14-15 from:

Someone can update this section, but nohup is normally included with even the most minimal unix like systems.

to:

The nohup binary is normally included with even the most minimal unix like systems. With optware, slugos or debian, it's part of the coreutils package.

September 19, 2007, at 01:41 PM by fcarolo -- formatting
Changed line 89 from:
  1. in vi, issue the command - @:!chmod 660 /tmp/myvisession@ (NOTE: I couldn't get 640 to work for me)
to:
  1. in vi, issue the command - :!chmod 660 /tmp/myvisession (NOTE: I couldn't get 640 to work for me)
September 19, 2007, at 01:40 PM by fcarolo -- formatting, typos
Changed lines 9-10 from:

nohup is a command preventing the subsequent executing command from receiving some system Signals such as as HANGUP - hence NOHUP = no hangup. It's commonly used with the shell's standard job control since the execution will still occupy the executing prompt, for example, the ampersand to background a task. By default, all the stdout console output is redirected to nohup.out unless you redirect it yourself.

to:

nohup is a command preventing the subsequent executing command from receiving some system Signals such as HANGUP - hence NOHUP = no hangup. It's commonly used with the shell's standard job control since the execution will still occupy the executing prompt, for example, the ampersand to background a task. By default, all the stdout console output is redirected to nohup.out unless you redirect it yourself.

Changed lines 53-54 from:

If you are using Optware, just issue the command: ipkg install dtach

to:

If you are using Optware, just issue the command: ipkg install dtach

Changed line 56 from:
  • install the Optware feed (I did) and issue the command: /opt/bin/ipkg install dtach
to:
  • install the Optware feed (I did) and issue the command: /opt/bin/ipkg install dtach
Changed lines 59-60 from:

If you're using Debian, `apt-get install dtach` will install it

to:

If you're using Debian, apt-get install dtach will install it

Changed lines 80-81 from:

dtach -A -z /tmp/mydtachsocket bash

to:
  dtach -A -z /tmp/mydtachsocket bash
Changed lines 88-93 from:

1. dtach -A -z /tmp/myvisession vi log-or-filename

2. in vi, issue the command - : !chmod 660 /tmp/myvisession # (NOTE: I couldn't get 640 to work for me)

3. have your all your peers connect using: dtach -a /tmp/myvisession # now everyone can work the file or log

to:
  1. dtach -A -z /tmp/myvisession vi log-or-filename
  2. in vi, issue the command - @:!chmod 660 /tmp/myvisession@ (NOTE: I couldn't get 640 to work for me)
  3. have your all your peers connect using: dtach -a /tmp/myvisession # now everyone can work the file or log
Changed lines 94-95 from:

You can try it out on from a couple of terminals on the same workstation without having to change permission, it's freaky cool. Just `dtach -A -z /tmp/mydtachsocket bash` in multipleconsoles.

to:

You can try it out on from a couple of terminals on the same workstation without having to change permission, it's freaky cool. Just dtach -A -z /tmp/mydtachsocket bash in multiple consoles.

Changed lines 98-101 from:

dtach -c -z /tmp/bgdtach myscript

make sure your script or command redirects it's output someplace else for review. It doesn't cache stdout & stderr for you. You would have to attach to see them if not captured.

to:
  dtach -c -z /tmp/bgdtach myscript

Make sure your script or command redirects it's output someplace else for review. It doesn't cache stdout & stderr for you. You would have to attach to see them if not captured.

Changed line 106 from:
  • if you use WiFi? connectivity which has a flaky connection, dtach (and screen) is a godsend
to:
  • if you use WiFi connectivity which has a flaky connection, dtach (and screen) is a godsend
Changed line 110 from:
  • console based apps which need to stay "alive" like: irc or other IM clients/bots, bitorrent, etc.
to:
  • console based apps which need to stay "alive" like: irc or other IM clients/bots, bittorrent, etc.
Changed line 127 from:
  • Make a ~/dtach or ~/.dtach to store all your dtach sessions/unix sockets and use it. Check it for lingering sessions
to:
  • Make a ~/dtach or ~/.dtach to store all your dtach sessions/unix sockets and use it. Check it for lingering sessions
Changed lines 132-133 from:
  • Use -c create when issuing ssh remote commands if you need to revisit it later ( ssh user@host "dtach -c ~/dtach/taskname ScriptOrConsoleApp? )
to:
  • Use -c create when issuing ssh remote commands if you need to revisit it later (ssh user@host "dtach -c ~/dtach/taskname ScriptOrConsoleApp")
Changed line 137 from:
  • http ://dtach.sourceforge.net/
to:
  • http://dtach.sourceforge.net/
Changed lines 139-140 from:
  • http ://penguin-soft.com/penguin/man/1/dtach.html
to:
  • http://penguin-soft.com/penguin/man/1/dtach.html
Changed lines 148-153 from:

Unfortunately, you may end up with a hand cramp if you're managing several screen screens/tab at a time. Everything is Ctrl+Key CommandKey? combo sequence.

Installation ( much like dtach )

If you are using Optware, just issue the command: ipkg install screen

to:

Unfortunately, you may end up with a hand cramp if you're managing several screen screens/tab at a time. Everything is Ctrl+Key CommandKey combo sequence.

Installation (much like dtach)

If you are using Optware, just issue the command: ipkg install screen

Changed line 155 from:
  • install the Optware feed (I did) and issue the command: /opt/bin/ipkg install screen
to:
  • install the Optware feed (I did) and issue the command: /opt/bin/ipkg install screen
Changed lines 158-159 from:

If you're using Debian, `apt-get install screen` will install it

to:

If you're using Debian, apt-get install screen will install it

Changed lines 170-171 from:

To create a new screen, press Ctrl+A C . You can do this any number of times.

to:

To create a new screen, press Ctrl+A C. You can do this any number of times.

Changed lines 186-187 from:
  • You'll probably created a custom ~/.screenrc file. Many styles include "tabs", clocks, hostname, and other notables. Searching the internet for screenrc will turn up more than enough.
to:
  • You'll probably created a custom ~/.screenrc file. Many styles include "tabs", clocks, hostname, and other notables. Searching the internet for screenrc will turn up more than enough.
Changed line 191 from:
  • http ://www.linuxmanpages.com/man1/screen.1.php
to:
  • http://www.linuxmanpages.com/man1/screen.1.php
Added line 195:
September 19, 2007, at 08:37 AM by markstinson --
Changed lines 192-195 from:

http://en.wikipedia.org/wiki/GNU_Screen - lists official site, and other resources http ://www.linuxmanpages.com/man1/screen.1.php http://www.linuxjournal.com/article/6340

to:
  • http://en.wikipedia.org/wiki/GNU_Screen - lists official site, and other resources
  • http ://www.linuxmanpages.com/man1/screen.1.php
  • http://www.linuxjournal.com/article/6340
September 19, 2007, at 08:36 AM by markstinson --
Changed lines 22-23 from:
   ps -fu username # will show your processes not attached to any shell. Important for tracking down nohup processes to kill.
to:
   ps -fu username # will show your processes not attached to any shell. 
                   # Important for tracking down nohup processes to kill.
September 19, 2007, at 08:34 AM by markstinson --
Deleted line 1:
Changed lines 18-23 from:

nohup cmd & # stdout is redirected to nohup.out

nohup cmd > std.out 2> std.err &

ps -fu username # will show your processes not attached to any shell. Important for tracking down nohup processes to kill.

to:
   nohup cmd & # stdout is redirected to nohup.out

   nohup cmd > std.out 2> std.err &

   ps -fu username # will show your processes not attached to any shell. Important for tracking down nohup processes to kill.
Deleted line 28:
Changed lines 68-69 from:
  • build for
to:
  • build for the NSLU2
Changed lines 88-92 from:

2. in vi, issue the command - : !chmod 660 /tmp/myvisession

    (NOTE: I couldn't get 640 to work for me)

3. have your all your peers connect using: dtach -a /tmp/myvisession

    now everyone can work the file or log
to:

2. in vi, issue the command - : !chmod 660 /tmp/myvisession # (NOTE: I couldn't get 640 to work for me)

3. have your all your peers connect using: dtach -a /tmp/myvisession # now everyone can work the file or log

Deleted line 155:
September 19, 2007, at 08:30 AM by markstinson --
Changed line 37 from:

--

to:
September 19, 2007, at 08:30 AM by markstinson --
Added lines 143-217:

screen (GNU screen)

About GNU screen

What's there to say? It's the granddaddy of screen multiplexers. It was written years ago in the age of dial-up to allow multiple consoles over a single terminal connection. It's still being actively developed and advanced today.

dtach is a 1-to-1 session manager. Screen takes over terminal management. It's highly configurable. Instead of re-hashing the many articles on screen, you can check out some links at the end of this post. And yes, screen allows you to share screen with others. It's a switch and managed differently than dtach.

Unfortunately, you may end up with a hand cramp if you're managing several screen screens/tab at a time. Everything is Ctrl+Key CommandKey? combo sequence.

Installation ( much like dtach )

If you are using Optware, just issue the command: ipkg install screen

If you are using SlugOS, you have two options:

  • install the Optware feed (I did) and issue the command: /opt/bin/ipkg install screen
  • compile, package and install your own version

If you're using Debian, `apt-get install screen` will install it

If you're using a major distro on your desktop, it should be found in your distro's repository

Building and Installation

Someone feel free to point to an article on how to build it.

Usage

Simply invoke: screen

To create a new screen, press Ctrl+A C . You can do this any number of times.

To switch between screens, press Ctrl+A #, where # is 0 through 9.

To close a screen, just log out. Note, just because you close 2, doesn't shift 3, 4 & 5 down. #2 is freed up, that's all.

Gotchas and idiosyncrasies

(there's more than this)

  • `screen` uses Ctrl+A by default for console switching. Bash however uses Ctrl+A to jump to the start of the line. This can be adjusted.
  • It intercepts quite a bit.
  • the session management is via the keyboard. It's no problem for those used to keyboard. (rhetorical) But how one scroll lines up and down without scrollbars after `cat`ing a file?

Tips and Suggestions

  • Read the man page. It's big.
  • You'll probably created a custom ~/.screenrc file. Many styles include "tabs", clocks, hostname, and other notables. Searching the internet for screenrc will turn up more than enough.

Additional References

http://en.wikipedia.org/wiki/GNU_Screen - lists official site, and other resources http ://www.linuxmanpages.com/man1/screen.1.php http://www.linuxjournal.com/article/6340

User Contributed Tips, Examples, URL references, etc.

The wall of shame. Feel free to shout out your tips and examples here so we can keep the above article from having 50 tips and examples in each section. Thanks.

nohup

nohup Tips

How I use nohup

dtach

dtach Tips

How I use dtach

screen

screen Tips

How I use screen

September 19, 2007, at 08:29 AM by markstinson --
Changed line 141 from:
  • https ://sourceforge.net/projects/dtach/
to:
  • https://sourceforge.net/projects/dtach/
September 19, 2007, at 08:28 AM by markstinson --
Added lines 139-142:
  • http://en.wikipedia.org/wiki/Dtach
  • http ://dtach.sourceforge.net/
  • https ://sourceforge.net/projects/dtach/
  • http ://penguin-soft.com/penguin/man/1/dtach.html
September 19, 2007, at 08:28 AM by markstinson --
Added lines 35-138:

dtach

--

About dtach

dtach originated as a minimalist alternative to screen. It allows you to spawn a shell or other command into its own detachable pseudo-terminal. It also allows you the ability to share your session with a cohort. It can be used anywhere from large corporate style servers to the lovable NSLU2 Slugs.

  • It doesn't interpret or intercept anything except a couple of control keybindings (Ctrl+\ , Ctrl+Z, Ctrl+L). Luckily, a couple of switches allows you to re-assign those controls and manage your attach/detachment.
  • It's small in size and load. After stripping an i386 build, it was only 10K !! Heck, the manpage is 5K.
  • Because it uses Unix sockets (as opposed to network sockets), security is controlled using regular file permissions and is localized to the box. Your secure connection is your problem. :-)
  • dtach let's you share the session. Ever try to troubleshoot over the phone using VNC or worse, MS Netmeeting, just for console stuff? (Screen can do this too)
  • It has no library dependencies so you can manually unpack and install your own personal copy in ~/bin if it's not installed on the system.

Now, you can return to interactive session of `mc`, Vim, or a compile, etc. no sweat. (Try a long compile on the Slug?)

In fact, this is probably the most extensive article you'll come across about using dtach. Most people use screen before realizing dtach is just enough - that is if they find out about dtach at all.

Installation

If you are using Optware, just issue the command: ipkg install dtach

If you are using SlugOS, you have two options:

  • install the Optware feed (I did) and issue the command: /opt/bin/ipkg install dtach
  • compile, package and install your own version

If you're using Debian, `apt-get install dtach` will install it

If you're using a major distro on your desktop, it should be found in your distro's repository

Building and Installation

If you want to compile, package and install your own version (untried for Slug)

  • Read the HowTo's on setting up your native or cross-compile environment
  • go to http://dtach.sourceforge.net for the latest stable release
  • build for

the build on a regular RHES Linux box for personal use was: ./configure; make; strip dtach; cp dtach ~/bin ; # as not to pollute the /usr/bin or /usr/local/bin system using `sudo make install`

Usage

Example one - a standard, detachable Bash session

This example launches a dtach session. If the unix socket exists, attach to it, otherwise create a new session/socket and execute bash.

dtach -A -z /tmp/mydtachsocket bash

Then to detach from your session you could just close your terminal application or you can press the default Ctrl+

Example two - a sharable Bash session

Say you don't care about a detachable session, but you want to share a Vi session with a co-worker in the same user group. No problem.

1. dtach -A -z /tmp/myvisession vi log-or-filename 2. in vi, issue the command - : !chmod 660 /tmp/myvisession

    (NOTE: I couldn't get 640 to work for me)

3. have your all your peers connect using: dtach -a /tmp/myvisession

    now everyone can work the file or log

Now both you and you co-worker can work together on the same file, seeing the same thing. The best part is, you don't have to restart your session - instant gratification - if you start out using dtach.

You can try it out on from a couple of terminals on the same workstation without having to change permission, it's freaky cool. Just `dtach -A -z /tmp/mydtachsocket bash` in multipleconsoles.

Example three - backgrounding like nohup

dtach -c -z /tmp/bgdtach myscript

make sure your script or command redirects it's output someplace else for review. It doesn't cache stdout & stderr for you. You would have to attach to see them if not captured.

Other Examples or situations

This list could be really long. It's up to you to try some out. Please add your suggestions and ideas at the end of the page. Many of these are applicable to screen as well.

  • if you use WiFi? connectivity which has a flaky connection, dtach (and screen) is a godsend
  • sharing the same terminal from multiple machines around the house
  • sharing troubleshooting screens, logs, etc
  • long compiles or installs
  • console based apps which need to stay "alive" like: irc or other IM clients/bots, bitorrent, etc.
  • your console based PIM, calendar, media clients, dashboards, etc
  • a console place holder or session manager - you've got to leave for work and want to return where you left off. Let it sit there idle.

Gotchas and idiosyncrasies

  • Using Ctrl+D to log out. This traditionally will send the HANGUP signal to your shell which then closes out the dtach session. Get ready to say "doh" ... it'll break you from that convenient habit. And it's embarrassing when giving a presentation or working in a classroom environment. BTW, remapping 'd' as your dtach key doesn't work either, I tried. :-)
  • Using Ctrl+Z to suspend a job. By default, dtach will accept that Ctrl+Z and suspend _itself_, thank you very much - not. You can turn off that annoying feature using the'-z' switch.
  • Using Ctrl+L to refresh. Works great. However, if your console GUI app doesn't refresh right away, it gets "wonky", Ctrl+L will clean it up. However, it may take longer for the app to resize itself to match your terminal. You can control the refresh method. Definitely look over it's manpage and dtach --help. There's not much too it. I discovered this using Midnight Commander `mc` ftp'ing some files.
  • NOTE: dtach hasn't really been updated since 2004. It hasn't been ported to many POSIX systems, for example AIX, as they have different psuedo-terminals.

Tips and Suggestions

  • Read the minimal docs and experiment. There's other ways to control the refresh/redraw, re-mapping the detach key, etc.
  • Make a ~/dtach or ~/.dtach to store all your dtach sessions/unix sockets and use it. Check it for lingering sessions
  • Give your dtach socket handles sensible names. Heck, close a session and create a new one if you change major tasks
  • Make some aliases for instant dtach terminals or frequent commands.
  • Come up with some prompt magic to keep yourself informed of when you're using `dtach` and which Unix Socket it's on.
  • Create some scripts so that your login shell becomes a pre-dtached bash shell - like a dtach manager.
  • Use -c create when issuing ssh remote commands if you need to revisit it later ( ssh user@host "dtach -c ~/dtach/taskname ScriptOrConsoleApp? )

Additional References

September 19, 2007, at 08:26 AM by markstinson --
Deleted lines 0-1:
Changed lines 31-34 from:

http://en.wikipedia.org/wiki/Nohup http://www.idevelopment.info/data/Unix/General_UNIX/GENERAL_RunningUNIXCommandsImmunetoHangups_nohup.shtml http://www.computerhope.com/unix/unohup.htm http://www.google.com/search?q=nohup+example&btnG=Search&hl=en

to:
  • http://en.wikipedia.org/wiki/Nohup
  • http://www.idevelopment.info/data/Unix/General_UNIX/GENERAL_RunningUNIXCommandsImmunetoHangups_nohup.shtml
  • http://www.computerhope.com/unix/unohup.htm
  • http://www.google.com/search?q=nohup+example&btnG=Search&hl=en
September 19, 2007, at 08:25 AM by markstinson --
Added lines 8-36:

nohup and Standard job control

About nohup

nohup is a command preventing the subsequent executing command from receiving some system Signals such as as HANGUP - hence NOHUP = no hangup. It's commonly used with the shell's standard job control since the execution will still occupy the executing prompt, for example, the ampersand to background a task. By default, all the stdout console output is redirected to nohup.out unless you redirect it yourself.

This is fine for most situations not requiring user interaction or response.

Building and Installation

Someone can update this section, but nohup is normally included with even the most minimal unix like systems.

Usage examples

nohup cmd & # stdout is redirected to nohup.out

nohup cmd > std.out 2> std.err &

ps -fu username # will show your processes not attached to any shell. Important for tracking down nohup processes to kill.

Tips and Suggestions

  • Learn to use your shell's job control such as `fg`, `bg` and & ( read your shell's manpage and check your docs )
  • Learn to use Signal control

Additional References

http://en.wikipedia.org/wiki/Nohup http://www.idevelopment.info/data/Unix/General_UNIX/GENERAL_RunningUNIXCommandsImmunetoHangups_nohup.shtml http://www.computerhope.com/unix/unohup.htm http://www.google.com/search?q=nohup+example&btnG=Search&hl=en

September 19, 2007, at 08:24 AM by markstinson -- adding new howto - KeepRemoteConsoleSessionRunning for nohup, dtach and screen
Changed lines 1-7 from:

Place holder

to:

KeepRemoteConsoleSessionRunning

There are many different reasons and situations you may want to keep your current terminal activity or execution running. Luckily, there are more than one way of managing the process or application.

  • nohup and standard job control
  • dtach
  • screen (GNU screen)
September 19, 2007, at 08:23 AM by markstinson -- initial creation on using nohup, dtach and screen
Added line 1:

Place holder

view · edit · print · history · Last edited by MarkStinson.
Based on work by BrianZhou, Fred, bla, asdf, MarkStinson, markstinson, fcarolo, and cbase.
Originally by markstinson.
Page last modified on June 13, 2008, at 06:44 PM