Example #1) 'Unmodified' PuTTY login to default directory >> Enter 'Top' Command >>> enter 'q' = You land back at the root (default) directory.

Example #2) Use the PuTTY settings option remote command = "Top" >> From the top enter 'q' = Instant logout (session closed)

Example #3) Same as #2 w/ 1 difference: PuTTY remote command = echo "Hello World!"; top;

^^^ re #3: I was thinking the brief pause to echo (for example) Hello World! would simulate Example #1 and after 'q' I would land back "Home", but the result was equal to #2 (session closed)

Quick Summary: This is one of those things which "should be simple"; How do I login straight to the 'top' and still have a session after 'q'?


.. EDIT: An amazingly fast flood of answers for this time of morning!

logout: not login shell: use `exit'

Here is the exact code which is working best:

top; /bin/bash -il

I'm also testing Phil's code now, his is virtually the same.


SSH executes the remote command by passing it to your configured shell to execute. If you open PuTTY with the the remote command top, then SSH will run the following:

$SHELL -c "top"

When run with the -c argument, the shell terminates once the command terminates, which causes your session to end.

To run top and then stay logged in, you can use the remote command top; $SHELL -l. This will run top and then start a login shell.

  • 1
    +1 for maintaining the existing shell. (rather than just assuming bash, like me) Jan 31 '11 at 10:33
  • Yours creates the type of session I'm used to, w/ a 'normal' logout vs. the message "logout: not login shell: use `exit'" Jan 31 '11 at 10:42

It's logging you out because you told putty to run one and only one command in your remote session, which is top.

You could make a file ~/bin/topsh, which said

exec bash

and use putty's "remote command" option to try running that; once you leave top, the session will be overwritten with a bash shell, and when you leave that, you should be automatically logged out.


Try changing your remote command to

top; bash

One the remote command exits, the shell it runs in will also close, which ends your session. If your last command is top, then existing that will always close your session.

Try top; bash as your command and you'll run a shell after top exits. The session will only then end once you've closed that bash session.


The best bet is to look at top's batch mode. You can do something like top -n1 -b to get a snapshot of the system. I'm not aware of anyway to get top to stop clearing the screen on exit.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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