Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
ssh remotehost "remote_command" | more

This executes remote_command on remotehost, and paginates the output of remote_command. If the user is unwilling to scroll through all the pages, he might press q at the --MORE-- prompt. Unfortunately this doesn't stop the ssh process (and the remote command). The user have to press ^C to actually terminate the processes. When user presses q more terminates and ssh gets SIGPIPE but continues as remote_command didn't finish executing. Is there any way I can terminate ssh and remote execution when the user quits the pager? I don't want the user to press ^C as he wouldn't be required to do so if a local file was being catted (in fact he wouldn't know this command is being executed over a ssh tunnel remotely).

share|improve this question

Why not just change the command to call more on the remote server? Also you will have to force a pty as wfaulk mentioned. Assuming it is another unix system this should be fine. i.e.

ssh -t name@system "command | more"

Fyi. less is more :)

share|improve this answer
Forcing a terminal is messing up with newlines etc. And again, pagination on remote side is not good as I am on a terminal (router CLI shell) which has configurable number of lines per page - and that can't be communicated to pager on remote side. – Anonymous Oct 17 '09 at 13:32

I haven't tested this, but try getting a pty from the remote machine by passing the '-t' flag to ssh.

share|improve this answer

Your Answer


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