Koozali.org: home of the SME Server

Redirecting console output over SSH

Offline pwalter

  • *
  • 38
  • +0/-0
Redirecting console output over SSH
« on: April 25, 2009, 07:12:02 AM »
This isn't a question on how to use a client like PuTTY to access a terminal session on SME over SSH. What I am looking for is a solution which "forks" the primary console input and output to a remote terminal program over SSH, while allowing the primary console to be active simultaneously - similar to a remote control program for Windows. Why do I need it? Well, if you use PuTTY to connect to a console session, and start a program running, if the ssh connection fails, the console session dies and kills the program. I need to find a way to keep a persistent console session and re-connect to it if the connection fails. There is a lot of stuff on the internet on how to do it over a COM port, but almost nothing about how to do it over SSH. Any pointers would be gratefully appreciated.

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: Redirecting console output over SSH
« Reply #1 on: April 25, 2009, 07:19:05 AM »
hi

man screen is all you need ;-)

HTH
ciao
Stefano

Offline pwalter

  • *
  • 38
  • +0/-0
Re: Redirecting console output over SSH
« Reply #2 on: April 25, 2009, 07:21:59 AM »
man screen is all you need ;-)
Duh!
So much to learn, so little time .... Thanks, Stefano

Offline pwalter

  • *
  • 38
  • +0/-0
Re: Redirecting console output over SSH
« Reply #3 on: April 25, 2009, 07:53:35 AM »
man screen is all you need ;-)
Well, maybe not so much. From my reading, it seems that screen will create a virtual terminal that can be detached - and that is part of the solution, but I want to "mirror" the existing physical console, not create a new virtual terminal. If screen *will* do that, can you give me pointers on how to use it?

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: Redirecting console output over SSH
« Reply #4 on: April 25, 2009, 08:51:17 AM »
If screen *will* do that, can you give me pointers on how to use it?
AFAIK screen won't do that, nor would SSH for all I know. I am not sure if what you are wishing for is even possible.
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline pwalter

  • *
  • 38
  • +0/-0
Re: Redirecting console output over SSH
« Reply #5 on: April 26, 2009, 08:51:26 PM »
Cactus, Stefano, thank you.

Aargh. It does seem to be "possible", but very difficult - it seems that a deliberate design decision was made to stop possible "hijacking" of the system console. I think that is short-sighted, but what do I know :-) Using the screen command does not exactly meet my needs, but it may be good enough. Pointers for others who may have the same need using PuTTY:
- To start a new screen, simply type "screen" and a new session will open.
- To exit the new session, leaving it running, simply close the Putty window
- To reattach to previous sessions, use screen -list first to list the sessions, then use screen -r <sessionname>
- To terminate the screen session, simply use "exit" or Ctrl-D at the bash prompt.

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: Redirecting console output over SSH
« Reply #6 on: April 27, 2009, 02:20:44 AM »
Aargh. It does seem to be "possible", but very difficult

No, it's not possible (without significant modification).

Quote
- it seems that a deliberate design decision was made to stop possible "hijacking" of the system console.

No, it's that no specific design has been done to make what you want possible. The 'console' needs to be constantly available. That pretty much precludes anything via network. Console is either keyboard plus VGA, or it is serial.

You can purchase add-on hardware which allows a serial console accessible via network. And if you have a fancy HP, Sun or IBM server, you can have a virtual console accessible via the network (which runs on an embedded process on the motherboard).


Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: Redirecting console output over SSH
« Reply #7 on: April 27, 2009, 02:26:03 AM »
Well, if you use PuTTY to connect to a console session, and start a program running, if the ssh connection fails, the console session dies and kills the program.

Not if you use "nohup".

Quote
I need to find a way to keep a persistent console session and re-connect to it if the connection fails.

screen will do that. You say screen doesn't work for you because you want to "mirror" the current console - but I don't see where you say why. What problem are you trying to solve which screen doesn't solve?

Offline pwalter

  • *
  • 38
  • +0/-0
Re: Redirecting console output over SSH
« Reply #8 on: April 27, 2009, 04:22:00 AM »
Not if you use "nohup".
Charlie, thanks for the education. I had never heard of "nohup" before - gotta find the time to enroll in Linux Administration school soon. :-)  I'm sure one of these days I'll find an advert for one on contribs.org .... or maybe you should start an online school  yourself :grin:

Sometimes, it would be nice to be able to demonstrate to someone else at the other end what you are doing and why - to remotely control their console for them. It's not a biggie; I am simply used to having that facility when controlling Windows (and Linux X clients) remotely. I understand the point about using a serial link, but, frankly, if the server / network is behaving so badly that I can't get a secure connection over the network, I might as well pay a pyhsical visit anyway (or have soneone else do it). From now on, it will be using SME VM's embedded in gui-based hypervisors if I feel I really need that approach.

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: Redirecting console output over SSH
« Reply #9 on: April 27, 2009, 07:04:37 PM »
I'm sure one of these days I'll find an advert for one on contribs.org .... or maybe you should start an online school  yourself :grin:
Nope, commercial posts are prohibited and will be removed.

Sometimes, it would be nice to be able to demonstrate to someone else at the other end what you are doing and why - to remotely control their console for them. It's not a biggie; I am simply used to having that facility when controlling Windows (and Linux X clients) remotely. I understand the point about using a serial link, but, frankly, if the server / network is behaving so badly that I can't get a secure connection over the network, I might as well pay a pyhsical visit anyway (or have soneone else do it). From now on, it will be using SME VM's embedded in gui-based hypervisors if I feel I really need that approach.
You can still start a screen and show them in there, they can attach to that screen as well from their end and see what you are doing in the screen session, just like you can attach to a screen session they start. So it is still possible it just needs a little bit of attention and work before starting off.

Not sure if it works but perhaps you can set the default shell of the admin and/or root user to be screen, so they always start in a screen terminal. I have not tested this so I am not sure if that will work.
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: Redirecting console output over SSH
« Reply #10 on: April 27, 2009, 07:09:39 PM »
Some interesting features of screen that might be useful in your situation: http://www.linux.com/feature/56443
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline pwalter

  • *
  • 38
  • +0/-0
Re: Redirecting console output over SSH
« Reply #11 on: April 27, 2009, 07:40:56 PM »
Nope, commercial posts are prohibited and will be removed.
Off-topic, to be sure, but this policy probably needs reviewing. It seems to me that support dollars for this site, and SME Server as a whole, could be generated that way. Centos.org supports raw advertising, "sponsors", and uses Google ads. Who do I take the matter up with?

Offline pwalter

  • *
  • 38
  • +0/-0
Re: Redirecting console output over SSH
« Reply #12 on: April 27, 2009, 07:41:52 PM »
Some interesting features of screen that might be useful in your situation: http://www.linux.com/feature/56443
Cactus, that is exactly what I was looking for. Thank you very much.