blackpoll
Posts: 11
Joined: Thu Nov 24, 2016 8:21 pm

Start Application via SSH?

Thu Nov 24, 2016 8:27 pm

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
Posts: 680
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Elescalador

Thu Nov 24, 2016 10:11 pm

What is the application?
My Autonomous Robot Project and a few of my other projects below.

https://lloydbrombach.wordpress.com/

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

Re: Start Application via SSH?

Thu Nov 24, 2016 10:41 pm

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

blackpoll
Posts: 11
Joined: Thu Nov 24, 2016 8:21 pm

Re: Elescalador

Fri Nov 25, 2016 12:11 am

ElEscalador wrote:What is the application?
Calibre

blackpoll
Posts: 11
Joined: Thu Nov 24, 2016 8:21 pm

Re: Start Application via SSH?

Fri Nov 25, 2016 12:13 am

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.

ghans
Posts: 7873
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Start Application via SSH?

Fri Nov 25, 2016 6:36 am

Code: Select all

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


ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

User avatar
dasmanul
Posts: 502
Joined: Wed Sep 30, 2015 10:20 am
Location: Frankfurt, Germany

Re: Start Application via SSH?

Fri Nov 25, 2016 9:55 am

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?

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Start Application via SSH?

Fri Nov 25, 2016 10:11 am

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.
Last edited by mfa298 on Fri Nov 25, 2016 6:30 pm, edited 1 time in total.

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

Re: Start Application via SSH?

Fri Nov 25, 2016 5:38 pm

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.

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

Re: Start Application via SSH?

Sat Nov 26, 2016 9:09 am

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.

blackpoll
Posts: 11
Joined: Thu Nov 24, 2016 8:21 pm

Re: Start Application via SSH?

Sat Nov 26, 2016 8:56 pm

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.

blackpoll
Posts: 11
Joined: Thu Nov 24, 2016 8:21 pm

Re: Start Application via SSH?

Sat Nov 26, 2016 9:18 pm

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

Martin Frezman
Posts: 1020
Joined: Mon Oct 31, 2016 10:05 am

Re: Start Application via SSH?

Sat Nov 26, 2016 10:46 pm

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.
If this post appears in the wrong forums category, my apologies.

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Start Application via SSH?

Sun Nov 27, 2016 9:08 am

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.

blackpoll
Posts: 11
Joined: Thu Nov 24, 2016 8:21 pm

Re: Start Application via SSH?

Sun Nov 27, 2016 3:50 pm

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

blackpoll
Posts: 11
Joined: Thu Nov 24, 2016 8:21 pm

Re: Start Application via SSH?

Sun Nov 27, 2016 3:54 pm

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.

blackpoll
Posts: 11
Joined: Thu Nov 24, 2016 8:21 pm

Re: Start Application via SSH?

Sun Nov 27, 2016 4:00 pm

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.

Martin Frezman
Posts: 1020
Joined: Mon Oct 31, 2016 10:05 am

Re: Start Application via SSH?

Sun Nov 27, 2016 4:05 pm

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.
If this post appears in the wrong forums category, my apologies.

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Start Application via SSH?

Sun Nov 27, 2016 4:35 pm

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.

blackpoll
Posts: 11
Joined: Thu Nov 24, 2016 8:21 pm

Re: Start Application via SSH?

Sun Nov 27, 2016 4:43 pm

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

User avatar
dasmanul
Posts: 502
Joined: Wed Sep 30, 2015 10:20 am
Location: Frankfurt, Germany

Re: Start Application via SSH?

Sun Nov 27, 2016 6:05 pm

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.

blackpoll
Posts: 11
Joined: Thu Nov 24, 2016 8:21 pm

Re: Start Application via SSH?

Sun Nov 27, 2016 6:46 pm

I need the GUI to be able to select and configure all of my RSS feeds.

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

Re: Start Application via SSH?

Sun Nov 27, 2016 7:33 pm

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

Martin Frezman
Posts: 1020
Joined: Mon Oct 31, 2016 10:05 am

Re: Start Application via SSH?

Mon Nov 28, 2016 7:58 am

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.
If this post appears in the wrong forums category, my apologies.

blackpoll
Posts: 11
Joined: Thu Nov 24, 2016 8:21 pm

Re: Start Application via SSH?

Tue Nov 29, 2016 2:11 pm

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.

Return to “Beginners”