Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

5 Answers

up vote 8 down vote accepted

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.

share|improve this answer
1  
+1 for maintaining the existing shell. (rather than just assuming bash, like me) –  SmallClanger 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'" –  This_Is_Fun Jan 31 '11 at 10:42
add comment

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

#!/bin/bash
top
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.

share|improve this answer
    
I'll use this idea for something else, thanks. –  This_Is_Fun Jan 31 '11 at 10:44
add comment

Try changing your remote command to

top; bash
share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
This isn't what the question is about. –  Dennis Williamson Jan 31 '11 at 15:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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