Page 1 of 2

Start Application via SSH?

Posted: Thu Nov 24, 2016 8:27 pm
by blackpoll
Greetings,

I have searched everywhere but can't seem to find an answer to this question.

If I am logging into my raspberry pi via ssh on my LAN, how do I start an application from the terminal? I'm not interested in using the application or viewing it from my computer, I just want to start it so it is running on the raspberry pi.

All the information I could find was related to people wanting to actually use the application GUI on their host computer or TV etc., but I don't need that function.

If I enter the application name in the terminal, it just tells me that I can't open the display which isn't what I want.

I hope that makes sense and thanks in advance!

Elescalador

Posted: Thu Nov 24, 2016 10:11 pm
by ElEscalador
What is the application?

Re: Start Application via SSH?

Posted: Thu Nov 24, 2016 10:41 pm
by richrarobi
Assuming you ran ssh from a system running X, (rather than one of those M$ thingies) as in this example from my Linux Mint to pi system a:-
ssh -l pi -Y a.local
the -Y is important (or use -X) note the uppercase. See viewtopic.php?f=66&t=11833&p=728951&hil ... fm#p728951

you can then run your X apps (such as pcmanfm &) so the output pops up on your Linux screen

Re: Elescalador

Posted: Fri Nov 25, 2016 12:11 am
by blackpoll
ElEscalador wrote:What is the application?
Calibre

Re: Start Application via SSH?

Posted: Fri Nov 25, 2016 12:13 am
by blackpoll
richrarobi wrote:Assuming you ran ssh from a system running X, (rather than one of those M$ thingies) as in this example from my Linux Mint to pi system a:-
ssh -l pi -Y a.local
the -Y is important (or use -X) note the uppercase. See viewtopic.php?f=66&t=11833&p=728951&hil ... fm#p728951

you can then run your X apps (such as pcmanfm &) so the output pops up on your Linux screen
I'm trying to run an application that is installed on the raspberry pi, not on the computer I am using to ssh into the pi. I just want to ssh into the pi, start Calibre so it is running and leave it running. Then end my ssh session and be done with Calibre left running on the pi.

Re: Start Application via SSH?

Posted: Fri Nov 25, 2016 6:36 am
by ghans

Code: Select all

ssh -x pi@IPADRESS calibre&
Both the small "x" and the ampersand are essential.


ghans

Re: Start Application via SSH?

Posted: Fri Nov 25, 2016 9:55 am
by dasmanul
For clarification: Does calibre have a GUI which you want to have displayed on a screen connected to the Pi or is it just a background process you want to run without seeing its output?

Re: Start Application via SSH?

Posted: Fri Nov 25, 2016 10:11 am
by mfa298
blackpoll wrote: If I am logging into my raspberry pi via ssh on my LAN, how do I start an application from the terminal? I'm not interested in using the application or viewing it from my computer, I just want to start it so it is running on the raspberry pi.
If this is a GUI (X) application and you want it running on the Pi's display try the following

Code: Select all

desktop $ ssh pi@raspberrypi.local
pi $ export DISPLAY=localhost:0
pi $ calibre &
For bonus points you might want to run the calibre process inside tmux or screen to allow you to reconnect to the controlling terminal at a later stage.

Re: Start Application via SSH?

Posted: Fri Nov 25, 2016 5:38 pm
by richrarobi
from "man ssh" :-
-X Enables X11 forwarding. This can also be specified on a per-host
basis in a configuration file.

X11 forwarding should be enabled with caution. Users with the
ability to bypass file permissions on the remote host (for the
user's X authorization database) can access the local X11 display
through the forwarded connection. An attacker may then be able
to perform activities such as keystroke monitoring.

For this reason, X11 forwarding is subjected to X11 SECURITY
extension restrictions by default. Please refer to the ssh -Y
option and the ForwardX11Trusted directive in ssh_config(5) for
more information.

-x Disables X11 forwarding.

-Y Enables trusted X11 forwarding. Trusted X11 forwardings are not
subjected to the X11 SECURITY extension controls.

Re: Start Application via SSH?

Posted: Sat Nov 26, 2016 9:09 am
by richrarobi
Then end my ssh session and be done with Calibre left running on the pi.
Unless you keep your command running with something like nohup e.g.

Code: Select all

nohup python3 zrep.py & 
leaves the app running in background
(May work with calibre, not tried)
or
Use a utility such as "screen" which probably won't do this (keeping app open) as it is for reconnect I believe (I don't use it), the application will stop as soon as you disconnect your ssh session.

Re: Start Application via SSH?

Posted: Sat Nov 26, 2016 8:56 pm
by blackpoll
dasmanul wrote:For clarification: Does calibre have a GUI which you want to have displayed on a screen connected to the Pi or is it just a background process you want to run without seeing its output?
I don't need to use the Calibre GUI once it is started on the pi, it just needs to run as a background process without seeing its output.

If I attach a monitor to the pi, I'll of course see the Calibre GUI running, but I don't need that.

Re: Start Application via SSH?

Posted: Sat Nov 26, 2016 9:18 pm
by blackpoll
Perhaps some more clarification would be helpful and others may want to do this. Calibre will automatically monitor and download all RSS feeds of your choice and automatically email them to your Kindle.

The purpose of leaving it running on a headless pi is to perform the above for me.

Yes, I can just plug in a monitor to the pi and start calibre, and then unplug the monitor and leave the pi running. But it would be easier for me to SSH into the pi and start calibre without having to use a monitor.

I'm using Ubuntu 16.04 on my main machine that I would use to ssh into the pi. I would have to end my ssh session and close the terminal however leaving calibre running on the headless pi.

that is the best I can explain it. thanks

Re: Start Application via SSH?

Posted: Sat Nov 26, 2016 10:46 pm
by Martin Frezman
First, let me say that this thread is a lot like another one, where I gave pretty much the same advice.

Second, I think that the real, long term, answer to your question is to figure out how to make this program run automatically on startup. Unless there is something you haven't told us yet, there doesn't seem to be any reason why you need to launch it manually - that is, launch sometime after the machine is powered on.

That said, the next key question is: Does this program *require* a GUI - that is, will it fail to launch if it is not connected to an X session? Will the program crash ("abend") if the X GUI goes away sometime after launch?

If the answer to all of these questions is "Yes", then you probably will need to investigate a VNC-type solution - that is, where you connect in via VNC, with a full X session going, launch the program, then disconnect from VNC, leaving the stuff running on the "virtual" X display. Note that you could actually do it either way - either the "x11vnc" way or the "virtual" way. Either way should work.

If not, though, then a SSH/screen approach would probably work. That is, if you can get the program to run without needing a GUI.

Re: Start Application via SSH?

Posted: Sun Nov 27, 2016 9:08 am
by mfa298
blackpoll wrote:Perhaps some more clarification would be helpful and others may want to do this. Calibre will automatically monitor and download all RSS feeds of your choice and automatically email them to your Kindle.

The purpose of leaving it running on a headless pi is to perform the above for me.

Yes, I can just plug in a monitor to the pi and start calibre, and then unplug the monitor and leave the pi running. But it would be easier for me to SSH into the pi and start calibre without having to use a monitor.
My answer above does exactly that as long as you have an X server (and probably a logged in session) on the Pi. If you don't have a logged in X session running on the Pi you'll have issues running any gui application.

A better solution might be looking for an alternative application that does the same thing but that doesn't need a gui. Running an X server and gui that never get looked at seems fairly wasteful of resources.

Re: Start Application via SSH?

Posted: Sun Nov 27, 2016 3:50 pm
by blackpoll
mfa298 wrote:
blackpoll wrote:Perhaps some more clarification would be helpful and others may want to do this. Calibre will automatically monitor and download all RSS feeds of your choice and automatically email them to your Kindle.

The purpose of leaving it running on a headless pi is to perform the above for me.

Yes, I can just plug in a monitor to the pi and start calibre, and then unplug the monitor and leave the pi running. But it would be easier for me to SSH into the pi and start calibre without having to use a monitor.
My answer above does exactly that as long as you have an X server (and probably a logged in session) on the Pi. If you don't have a logged in X session running on the Pi you'll have issues running any gui application.

A better solution might be looking for an alternative application that does the same thing but that doesn't need a gui. Running an X server and gui that never get looked at seems fairly wasteful of resources.
I tried your explanation and here is the terminal output:

Code: Select all

pi@raspberrypi:~ $ export DISPLAY=localhost:0
pi@raspberrypi:~ $ calibre &
[1] 1107
pi@raspberrypi:~ $ QXcbConnection: Could not connect to display localhost:0

Re: Start Application via SSH?

Posted: Sun Nov 27, 2016 3:54 pm
by blackpoll
ghans wrote:

Code: Select all

ssh -x pi@IPADRESS calibre&
Both the small "x" and the ampersand are essential.


ghans
I tried this command but it did not work.

Re: Start Application via SSH?

Posted: Sun Nov 27, 2016 4:00 pm
by blackpoll
richrarobi wrote:Assuming you ran ssh from a system running X, (rather than one of those M$ thingies) as in this example from my Linux Mint to pi system a:-
ssh -l pi -Y a.local
the -Y is important (or use -X) note the uppercase. See viewtopic.php?f=66&t=11833&p=728951&hil ... fm#p728951

you can then run your X apps (such as pcmanfm &) so the output pops up on your Linux screen
This successfully started calibre on the pi and the calibre GUI popped up on my main machine. However, calibre shut down when I exited the session so it did not leave it running which was my goal.

Re: Start Application via SSH?

Posted: Sun Nov 27, 2016 4:05 pm
by Martin Frezman
That's why any "solution" based on -X or -Y is obviously wrong for your use case. These responses (the ones mentioning -X or -Y) should be ignored.

You would do well to try to follow along with the advice I posted recently. Can you answer the questions posted therein? Thanks.

Re: Start Application via SSH?

Posted: Sun Nov 27, 2016 4:35 pm
by mfa298
blackpoll wrote:
mfa298 wrote:
blackpoll wrote:Perhaps some more clarification would be helpful and others may want to do this. Calibre will automatically monitor and download all RSS feeds of your choice and automatically email them to your Kindle.

The purpose of leaving it running on a headless pi is to perform the above for me.

Yes, I can just plug in a monitor to the pi and start calibre, and then unplug the monitor and leave the pi running. But it would be easier for me to SSH into the pi and start calibre without having to use a monitor.
My answer above does exactly that as long as you have an X server (and probably a logged in session) on the Pi. If you don't have a logged in X session running on the Pi you'll have issues running any gui application.

A better solution might be looking for an alternative application that does the same thing but that doesn't need a gui. Running an X server and gui that never get looked at seems fairly wasteful of resources.
I tried your explanation and here is the terminal output:

Code: Select all

pi@raspberrypi:~ $ export DISPLAY=localhost:0
pi@raspberrypi:~ $ calibre &
[1] 1107
pi@raspberrypi:~ $ QXcbConnection: Could not connect to display localhost:0
Is your pi running an X server (i.e. is it loading and logging into into a desktop gui), if not you're going to have issues.

Re: Start Application via SSH?

Posted: Sun Nov 27, 2016 4:43 pm
by blackpoll
Martin Frezman wrote:That's why any "solution" based on -X or -Y is obviously wrong for your use case. These responses (the ones mentioning -X or -Y) should be ignored.

You would do well to try to follow along with the advice I posted recently. Can you answer the questions posted therein? Thanks.
I didn't know the answer to the question about requiring a GUI or not but now I know. I followed your advice to login via VNC, started Calibre, and then exited the VNC session. It appears calibre is running successfully on the pi and the GUI did not pop up on the pi. So your solution has worked!

Here is the tutorial I used since I didn't know how to do a VNC session: https://quaintproject.wordpress.com/201 ... -linux-pc/

Please let me know if the above solution is a good way of doing VNC or if there is a "better" way.

The last thing would be to follow your advice and set it to start on startup so I wouldn't have to do VNC. I'll do some searching on how to do that.

thanks

Re: Start Application via SSH?

Posted: Sun Nov 27, 2016 6:05 pm
by dasmanul
If you don't need the GUI anyway, wouldn't the (headless) calibre-server be the program to start? That should eliminate the need for an X session completely.

Re: Start Application via SSH?

Posted: Sun Nov 27, 2016 6:46 pm
by blackpoll
I need the GUI to be able to select and configure all of my RSS feeds.

Re: Start Application via SSH?

Posted: Sun Nov 27, 2016 7:33 pm
by richrarobi
If you don't need the GUI anyway, wouldn't the (headless) calibre-server be the program to start? That should eliminate the need for an X session completely.
I agree with this - I run calibre and wasn't aware of the content server option (found under connect/share) - the web interface seems to let you manage feeds (?) a bit of research found this :-https://www.digitalocean.com/community/ ... untu-14-04

It seems you can run the web interface headless...... as mentioned by dasmanul above

Re: Start Application via SSH?

Posted: Mon Nov 28, 2016 7:58 am
by Martin Frezman
blackpoll wrote:It appears calibre is running successfully on the pi and the GUI did not pop up on the pi. So your solution has worked!
Great! Glad to hear that.
blackpoll wrote: Here is the tutorial I used since I didn't know how to do a VNC session: https://quaintproject.wordpress.com/201 ... -linux-pc/

Please let me know if the above solution is a good way of doing VNC or if there is a "better" way.
I looked at it - it looks fine. Some might say it is a little dated and that there are better ways (such as the newly revised and flashy "Real" VNC that comes with the latest Jessie), but it is certainly good enough for your purposes.

Re: Start Application via SSH?

Posted: Tue Nov 29, 2016 2:11 pm
by blackpoll
richrarobi wrote:
If you don't need the GUI anyway, wouldn't the (headless) calibre-server be the program to start? That should eliminate the need for an X session completely.
I agree with this - I run calibre and wasn't aware of the content server option (found under connect/share) - the web interface seems to let you manage feeds (?) a bit of research found this :-https://www.digitalocean.com/community/ ... untu-14-04

It seems you can run the web interface headless...... as mentioned by dasmanul above
Thank you for posting this tutorial, however, it is only for eBook management. My original post states that I use Calibre for automatic RSS feed download and automatic email to my kindle. I was not able to find any documentation on this feature with the server unless I am mistaken.