Remotely Opening a Linux Terminal

Stuck with a problem in your code? Seek help here.

Remotely Opening a Linux Terminal

Postby evansste » January 25th, 2017, 11:13 am

I'm trying to remotely open a terminal on a computer via SSH. Remotely accessing a computer via SSH is easy. But how do I open a remote terminal on that computer once I've logged into it? Please let me explain.

If I'm running Linux (Lubuntu) on a computer, and I already have a terminal open, I can type "lxterminal" in order to open a new terminal. However, if I'm remotely logged into a different computer and type the same thing, I get an error message. The message reads "(lxterminal:2668): Gtk-WARNING **: cannot open display:". I think I'm getting this message because the remote computer thinks I want to open a new terminal on my local computer. But that's not what I want to do. I want a terminal to open on that remote computer.

I've tried a few different workarounds. At first, I tried writing a script. The idea was to save a script file, on the remote computer, and then run that file from my local computer via SSH. The script would contain my "lxterminal" command. That didn't work. I get the same error message. Then I tried modifying the script so that it would wait 20 seconds, and then open the terminal. That way, after starting the script, I'd have enough time to log off. If I wasn't logged in, then maybe the remote terminal would open. That doesn't work either. What happens is the prompt disappears during the wait stage. So I'm unable to type "exit". If I close the local terminal window, the remote script stops running and it doesn't get to the next line, which is the one that tells it to open the terminal.

Linux is so dynamic that I have to believe there's a way to do this. Does anyone have any ideas on how to accomplish this? Thanks for your time.
evansste
 
Posts: 85
Joined: October 8th, 2014, 8:19 am

Re: Remotely Opening a Linux Terminal

Postby asheets » January 25th, 2017, 2:13 pm

start your ssh session with a -X switch to tunnel x windows through your ssh connection. Then you can start remote X applications to be displayed on your local workstation.
asheets
 
Posts: 298
Joined: February 17th, 2011, 4:30 pm

Re: Remotely Opening a Linux Terminal

Postby evansste » January 25th, 2017, 3:53 pm

Thanks for your response, asheets. Because of you, I'm closer than I've ever been to solving this problem. With "ssh -X remoteusername@hostID", I'm able to open a new terminal on my local computer, that is logged in to my remote computer. But is there a way to make it so that the window will open on the remote computer instead?

I've been reading about X-forwarding, and, although it must be unpopular, it seems as if such a thing may be possible. Opening a window from the remote computer so that it will appear locally, by far, is the more popular task. Everything I search only shows how to do that. Do you know how to get the remote terminal to open on the remote computer?

Thanks so much again for your help, and fast response. At least I know I'm on the right track.
evansste
 
Posts: 85
Joined: October 8th, 2014, 8:19 am

Re: Remotely Opening a Linux Terminal

Postby asheets » January 25th, 2017, 4:07 pm

OK, I misunderstood the problem... ssh -X won't help you at all.

Although I'm sure you have your reasons, it is beyond me why you'd want to open a terminal session on what is presumably an unmanned terminal...

evansste wrote:
I've tried a few different workarounds. At first, I tried writing a script. The idea was to save a script file, on the remote computer, and then run that file from my local computer via SSH. The script would contain my "lxterminal" command. That didn't work. I get the same error message. Then I tried modifying the script so that it would wait 20 seconds, and then open the terminal. That way, after starting the script, I'd have enough time to log off. If I wasn't logged in, then maybe the remote terminal would open. That doesn't work either. What happens is the prompt disappears during the wait stage. So I'm unable to type "exit". If I close the local terminal window, the remote script stops running and it doesn't get to the next line, which is the one that tells it to open the terminal.



Your script approach might work, if started with "nohup &" That way the script will continue running after you've exited the initiating remote session. But the way I figure it, you've also got to tell your script to open the terminal on the local host instead of the remote terminal that started the script. Presumably, you'd do that by changing the DISPLAY= variable from within your script to point the app to the correct display, but then you'd have to monkey around with xauth permissions and a whole bunch of other nonsense...


Maybe if you shared what your end goal is -- perhaps there is an easier way to accomplish what you want... Pictures would be nice if you have them....
asheets
 
Posts: 298
Joined: February 17th, 2011, 4:30 pm

Re: Remotely Opening a Linux Terminal

Postby evansste » January 25th, 2017, 5:22 pm

Thanks for the suggestion, asheets.

The "nohup &" idea didn't work; which is a little puzzling to me. I have a script on the remote computer, which simply waits 10 seconds and then opens a terminal. The contents of the script file is simple, and is as follows:

sleep 10
lxterminal

I then log in to the remote computer, which has this script, using ssh. Once logged in, I type "nohup /path/and/filename.sh &".
I get the following message:

[1] 1959
# nohup: ignoring input and appending output to 'nohup.out'

You said that this approach would require me to tell the script to open the terminal on the local host instead of the remote terminal that started the script. Is that why I'm getting this result? I didn't change any settings in any files, or anything. But if nohup will continue to run the script after the session has closed, and I want the terminal to open on the remote computer anyway, why would I have to tell it to open the terminal on the local host? Obviously there must be a lot going on behind the scenes, and you certainly know a lot more than I do. Just curious as to why that would be necessary. If it's too complicated to explain, that's okay. Just a little curious.

You asked what I'm trying to accomplish. You're basically right that my goal is to start a terminal on a remote computer, and leave that computer unmanned. Basically, once the terminal is open on the remote computer, it would be running Octave on that remote computer. My Octave program runs idly, waiting for me to send information to it. The program works on the information I send it, and then sends results back to my local computer. It's basically a workaround way to accomplish parallel computing without the need to run any other software like Oscar, or any MPI protocols. It works quite well, actually. However, the way things are setup now, I have to turn on the remote computer, make sure a second monitor is connected to it, open a terminal, and start Octave and my program, before I can run my other Octave program on my local computer. It gets old having to turn on the remote computer, so I was looking for a way to write a program which will allow me to automate the process of starting the computer, opening a terminal, and starting Octave. That way, the program on my local computer, can have complete control over the remote computer without me having to worry about it.

Sorry for such a long explanation, but that's what I'm trying to do. I'm already sending files to the remote computer, I just want to be able to start the whole process remotely too.

Thanks again for offering your suggestions on this. It's truly a big help.
evansste
 
Posts: 85
Joined: October 8th, 2014, 8:19 am

Re: Remotely Opening a Linux Terminal

Postby asheets » January 25th, 2017, 5:41 pm

What you really want is to start Octave on your 2nd computer as a daemon service, so that it is always running when the computer is on. No need for a terminal screen or anything like that. I refer you back to your previous thread on the subject where I recommended that you start Octave from an init.d or rc3.d script.

Alternatively, I would look at this: http://projects.moongate.ro/octave-daemon/


evansste wrote:You asked what I'm trying to accomplish. You're basically right that my goal is to start a terminal on a remote computer, and leave that computer unmanned. Basically, once the terminal is open on the remote computer, it would be running Octave on that remote computer. My Octave program runs idly, waiting for me to send information to it. The program works on the information I send it, and then sends results back to my local computer. It's basically a workaround way to accomplish parallel computing without the need to run any other software like Oscar, or any MPI protocols. It works quite well, actually. However, the way things are setup now, I have to turn on the remote computer, make sure a second monitor is connected to it, open a terminal, and start Octave and my program, before I can run my other Octave program on my local computer. It gets old having to turn on the remote computer, so I was looking for a way to write a program which will allow me to automate the process of starting the computer, opening a terminal, and starting Octave. That way, the program on my local computer, can have complete control over the remote computer without me having to worry about it.
asheets
 
Posts: 298
Joined: February 17th, 2011, 4:30 pm

Re: Remotely Opening a Linux Terminal

Postby evansste » January 25th, 2017, 8:24 pm

Thanks, asheets.

Essentially, my problem is now solved after going back to the idea which we had talked about before -- having Octave start automatically when the computer boots up.

I was running things like that for a while, but only learned how to start xterm rather than lxterminal. It worked pretty well, for a while, until it started misbehaving.

I like the idea of having the option to start the computer, and run things manually if I wanted. There have been times when I've turned on the remote computer, manually, and didn't want Octave to start. That's why I figured I'd look into a way for my program to start the computer and start octave, on its own, when I start a program. In the end, I ended up going back to setting it up so that xterm starts automatically, but it now runs my script which starts lxterminal, which then starts Octave. So I think this setup should work okay.

I started looking at the idea of running the daemon. However, things have been running so smoothly with separate instances of Octave, that I may stick with that. It may be a little more inefficient, but its certainly very stable, not to mention the fact that I'm familiar with it. It's good to know about the daemon, though. I first learned about Octave on this forum, but didn't want to leave MATLAB. I'm glad I eventually decided to switch. So you never know. Change is sometimes good.

Anyway, thanks so much for your help. As usual, I've learned a lot again by coming to this forum.
evansste
 
Posts: 85
Joined: October 8th, 2014, 8:19 am

Re: Remotely Opening a Linux Terminal

Postby asheets » January 25th, 2017, 8:49 pm

evansste wrote:I like the idea of having the option to start the computer, and run things manually if I wanted. There have been times when I've turned on the remote computer, manually, and didn't want Octave to start. That's why I figured I'd look into a way for my program to start the computer and start octave, on its own, when I start a program. In the end, I ended up going back to setting it up so that xterm starts automatically, but it now runs my script which starts lxterminal, which then starts Octave. So I think this setup should work okay..



Look into xinetd, which if set up properly can start a daemon on demand (i.e. when a remote program tries to contact it over the network).
asheets
 
Posts: 298
Joined: February 17th, 2011, 4:30 pm


Return to Help Me! Software

Who is online

Users browsing this forum: No registered users and 2 guests