Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

determining whether running remotely

46 views
Skip to first unread message

Russ P.

unread,
Aug 11, 2016, 6:50:36 PM8/11/16
to
I wrote a program that generates pdf files containing many plots. It can take anywhere from less than a minute to several hours to run. When I run it locally, I want the pdf files to come up automatically. When I run it remotely, however, I don't want the pdf files to come up because the pdf viewer takes ridiculously long to display. In bash, what is the simplest way to determine whether I am running remotely or not? Thanks.

Bit Twister

unread,
Aug 11, 2016, 7:09:53 PM8/11/16
to
On Thu, 11 Aug 2016 15:50:31 -0700 (PDT), Russ P. wrote:
> I wrote a program that generates pdf files containing many plots. It can take anywhere from less than a minute to several hours to run. When I run it locally, I want the pdf files to come up automatically. When I run it remotely, however, I don't want the pdf files to come up because the pdf viewer takes ridiculously long to display. In bash, what is the simplest way to determine whether I am running remotely or not? Thanks.

Since I use ssh for remote login, I check $SSH_CLIENT
to determin is I was local or had used ssh to get in.

Russ P.

unread,
Aug 11, 2016, 11:07:05 PM8/11/16
to
I am also using ssh, and that seems like a good idea. Thanks.

lawren...@gmail.com

unread,
Aug 12, 2016, 5:19:04 AM8/12/16
to
On Friday, August 12, 2016 at 11:09:53 AM UTC+12, Bit Twister wrote:
> Since I use ssh for remote login, I check $SSH_CLIENT
> to determin is I was local or had used ssh to get in.

The problem is, all that tells you is whether it’s a local or remote connection, it doesn’t tell you the speed of the connection.

j...@j.org

unread,
Aug 12, 2016, 10:32:09 AM8/12/16
to
Another related question: When I do 'ssh -X' into a remote shell, how
to start an X application in the host of the Xserver (using the same
Xserver display)?

It should be possible because firefox by default when invoked under a
'ssh -X' session would start a firefox process running on the Xserver
host (that option is overriden with the firefox -no-remote option).

hymie!

unread,
Aug 12, 2016, 12:28:25 PM8/12/16
to
In our last episode, the evil Dr. Lacto had captured our hero,
Russ P. <Russ.P...@gmail.com>, who said:
> In bash, what is the
> simplest way to determine whether I am running remotely or not? Thanks.

Probably look at the tty you are using. When I run locally, I am using
(for example) /dev/tty0 . When I run remotely, I am using (for example)
/dev/pts/4 .

--hymie! http://lactose.homelinux.net/~hymie hy...@lactose.homelinux.net

Thomas 'PointedEars' Lahn

unread,
Aug 14, 2016, 11:07:57 AM8/14/16
to
j...@j.org wrote:

> Another related question: When I do 'ssh -X' into a remote shell, how
> to start an X application in the host of the Xserver (using the same
> Xserver display)?

Observing Internet standards would get you a long way towards a useful
answer. That said, I do not think this is on-topic here.

> It should be possible because firefox by default when invoked under a
> 'ssh -X' session would start a firefox process running on the Xserver
> host (that option is overriden with the firefox -no-remote option).

No, as “firefox -help” tells you too, the “--no-remote” option prevents a
Firefox instance so started from accepting or sending “-remote” commands;
but since Firefox 9 not on all platforms.

--
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

Icarus Sparry

unread,
Aug 14, 2016, 1:42:30 PM8/14/16
to
On Fri, 12 Aug 2016 14:32:03 +0000, j wrote:

> Another related question: When I do 'ssh -X' into a remote shell, how to
> start an X application in the host of the Xserver (using the same
> Xserver display)?
>
> It should be possible because firefox by default when invoked under a
> 'ssh -X' session would start a firefox process running on the Xserver
> host (that option is overriden with the firefox -no-remote option).


Just start it!
The DISPLAY variable is set, usually to something like localhost:10
The ssh session will be set up to tunnel tcp port 6010 back to your
original X server, and (assuming xauth can be found on the remote
machine) the authentication will have been copied over.

Some versions of ssh and some programs require a '-Y' parameter as well,
this enables ForwardX11Trusted. In this mode the remote X client can do
more things, read the manual and consider the security of the remote
machine to decide if this is right for your circumstances.

Barry Margolin

unread,
Aug 14, 2016, 2:50:45 PM8/14/16
to
In article <slrnnqru94...@lactose.homelinux.net>,
hymie! <hy...@lactose.homelinux.net> wrote:

> In our last episode, the evil Dr. Lacto had captured our hero,
> Russ P. <Russ.P...@gmail.com>, who said:
> > In bash, what is the
> > simplest way to determine whether I am running remotely or not? Thanks.
>
> Probably look at the tty you are using. When I run locally, I am using
> (for example) /dev/tty0 . When I run remotely, I am using (for example)
> /dev/pts/4 .

You apparently don't use an X Windows terminal program when you run
locally.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Barry Margolin

unread,
Aug 14, 2016, 2:52:22 PM8/14/16
to
In article <542sz.55352$4a5....@fx16.iad>,
Icarus Sparry <i.spa...@gmail.com> wrote:

> On Fri, 12 Aug 2016 14:32:03 +0000, j wrote:
>
> > Another related question: When I do 'ssh -X' into a remote shell, how to
> > start an X application in the host of the Xserver (using the same
> > Xserver display)?
> >
> > It should be possible because firefox by default when invoked under a
> > 'ssh -X' session would start a firefox process running on the Xserver
> > host (that option is overriden with the firefox -no-remote option).
>
>
> Just start it!
> The DISPLAY variable is set, usually to something like localhost:10
> The ssh session will be set up to tunnel tcp port 6010 back to your
> original X server, and (assuming xauth can be found on the remote
> machine) the authentication will have been copied over.

That starts the program on the SSH server and displays it on the X
server, it doesn't run the program on the X server host.

Kenny McCormack

unread,
Aug 14, 2016, 3:59:46 PM8/14/16
to
In article <barmar-993D89....@88-209-239-213.giganet.hu>,
Barry Margolin <bar...@alum.mit.edu> wrote:
...
>> Just start it!
>> The DISPLAY variable is set, usually to something like localhost:10
>> The ssh session will be set up to tunnel tcp port 6010 back to your
>> original X server, and (assuming xauth can be found on the remote
>> machine) the authentication will have been copied over.
>
>That starts the program on the SSH server and displays it on the X
>server, it doesn't run the program on the X server host.

The problem is that no one knows what the OP really wants or what he's
talking about.

We've answered both of the possible questions, but we can't know which
answer he's looking for.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain in
compliance with said RFCs, the actual sig can be found at the following web address:
http://www.xmission.com/~gazelle/Sigs/Rorschach

Kenny McCormack

unread,
Aug 14, 2016, 4:05:02 PM8/14/16
to
In article <barmar-C00C60....@88-209-239-213.giganet.hu>,
Barry Margolin <bar...@alum.mit.edu> wrote:
>In article <slrnnqru94...@lactose.homelinux.net>,
> hymie! <hy...@lactose.homelinux.net> wrote:
>
>> In our last episode, the evil Dr. Lacto had captured our hero,
>> Russ P. <Russ.P...@gmail.com>, who said:
>> > In bash, what is the
>> > simplest way to determine whether I am running remotely or not? Thanks.
>>
>> Probably look at the tty you are using. When I run locally, I am using
>> (for example) /dev/tty0 . When I run remotely, I am using (for example)
>> /dev/pts/4 .
>
>You apparently don't use an X Windows terminal program when you run
>locally.

Again, this is a problem of definition. Nobody knows what "running
remotely" actually means.

--
b w r w g y b r y b

Icarus Sparry

unread,
Aug 14, 2016, 4:28:15 PM8/14/16
to
On Sun, 14 Aug 2016 14:52:19 -0400, Barry Margolin wrote:

> In article <542sz.55352$4a5....@fx16.iad>,
> Icarus Sparry <i.spa...@gmail.com> wrote:
>
>> On Fri, 12 Aug 2016 14:32:03 +0000, j wrote:
>>
>> > Another related question: When I do 'ssh -X' into a remote shell, how
>> > to start an X application in the host of the Xserver (using the same
>> > Xserver display)?
>> >
>> > It should be possible because firefox by default when invoked under a
>> > 'ssh -X' session would start a firefox process running on the Xserver
>> > host (that option is overriden with the firefox -no-remote option).
>>
>>
>> Just start it!
>> The DISPLAY variable is set, usually to something like localhost:10 The
>> ssh session will be set up to tunnel tcp port 6010 back to your
>> original X server, and (assuming xauth can be found on the remote
>> machine) the authentication will have been copied over.
>
> That starts the program on the SSH server and displays it on the X
> server, it doesn't run the program on the X server host.

True, I misread the question.

The OP will need to run an application on the X server host which accepts
commands and executes them. One way to do this would be to use tcl/tk and
the "send" command.

So for a proof of concept, assuming that "wish" is installed on both the
ssh server and the X server, create a file on the X server, e.g. /tmp/
receiver, with the following contents

#!/usr/bin/env wish
tk appname hostcmd
pack [button .b -text "Exit hostcmd" -command exit ]

and then run on the X server "wish /tmp/receiver" in a terminal window.
It should create a button that you can press, leave this running.

On the ssh host, run "wish", and at the "% " prompt type

send hostcmd {puts [exec /bin/pwd]}

and observe that in the terminal window associated with the "wish /tmp/
receiver" it will run the /bin/pwd command, and output it on that
terminal. (The simpler "send hostcmd exec /bin/pwd" will run the /bin/pwd
command on the X server but send the output to the window assocated with
the ssh host).

This can be extended to, for example'

send hostcmd exec xterm -T OnXserver &


Sorry for the original answer.


Kaz Kylheku

unread,
Aug 14, 2016, 9:16:08 PM8/14/16
to
What, nobody is correcting "X Windows" to "X Window System"?

Slow day in August ...

Aragorn

unread,
Aug 15, 2016, 12:14:31 AM8/15/16
to
On Monday 15 Aug 2016 03:16, Kaz Kylheku conveyed the following to
comp.unix.shell...

> What, nobody is correcting "X Windows" to "X Window System"?
>
> Slow day in August ...

I have given up on setting people straight on that horribly Microsoft-
conditioned Freudian slip. They probably don't even know *why* it is
called "the X Window System", and they keep on citing Wikipedia ─ the
source of all misinformation ─ as evidence of why "X Windows" is an
acceptable name for this display server.

For the luddites: The "X" in "X Window System" is not a reference to
UNIX. It's a letter of the alphabet, and it follows the letter "W". As
in "the W Window System", which already existed long before there ever
was such a thing as Microsoft Windows.

--
= Aragorn =

http://www.linuxcounter.net - registrant #223157

hymie!

unread,
Aug 15, 2016, 2:59:46 PM8/15/16
to
In our last episode, the evil Dr. Lacto had captured our hero,
Barry Margolin <bar...@alum.mit.edu>, who said:
> In article <slrnnqru94...@lactose.homelinux.net>,
> hymie! <hy...@lactose.homelinux.net> wrote:
>
>> In our last episode, the evil Dr. Lacto had captured our hero,
>> Russ P. <Russ.P...@gmail.com>, who said:
>> > In bash, what is the
>> > simplest way to determine whether I am running remotely or not? Thanks.
>>
>> Probably look at the tty you are using. When I run locally, I am using
>> (for example) /dev/tty0 . When I run remotely, I am using (for example)
>> /dev/pts/4 .
>
> You apparently don't use an X Windows terminal program when you run
> locally.

No, I do not. I rarely if ever directly sit down at the console of my
primary machine, and if I do, it's usually to quickly try to fix a network
problem.

That is why I took three opportunities to qualify my statement.
I have no specific way of knowing what method(s) he uses to connect
to his computer(s) or what device file(s) are used when he does so.
I suggested a method that might work.

--hymie! http://lactose.homelinux.net/~hymie hy...@lactose.homelinux.net

Russ P.

unread,
Aug 15, 2016, 3:44:58 PM8/15/16
to
Folks, the first reply to my original post answered my question.

Out of curiosity, I just checked back a few minutes ago to see if perhaps a better answer came up. I see nothing of much additional value, but I DO see a bunch of crap. That seems to be a pattern on this site.

Some of the regulars here are truly helpful, and I appreciate that, but others just want to spew crap and show off their own knowledge of unix shells. I think you know who you are. For those of you in the latter category, I suggest you grow up and get a life.

lawren...@gmail.com

unread,
Aug 15, 2016, 9:30:29 PM8/15/16
to
On Monday, August 15, 2016 at 1:16:08 PM UTC+12, Kaz Kylheku wrote:
> What, nobody is correcting "X Windows" to "X Window System"?

If you insist, I will start calling it “XWS”...

Also, this <https://en.wikipedia.org/wiki/Microsoft_Corp._v._Lindows.com,_Inc.>.

Janis Papanagnou

unread,
Aug 15, 2016, 10:17:05 PM8/15/16
to
On 16.08.2016 03:30, lawren...@gmail.com wrote:
> On Monday, August 15, 2016 at 1:16:08 PM UTC+12, Kaz Kylheku wrote:
>> What, nobody is correcting "X Windows" to "X Window System"?

Probably because it's an unnecessary nit-pick not considered worth
wasting bandwidth on that? - Everyone seems to have understood what
the poster meant with that term.

>
> If you insist, I will start calling it “XWS”...

I've never heard about the "X Window System" being called "XWS" and
I suggest to not introduce new and misleading abbreviations. If you
prefer a technical colloquial shortcut; [in appropriate contexts]
it's just called "X" (or "X11").

Janis

>
> [...]

Michael Paoli

unread,
Sep 5, 2016, 12:58:34 PM9/5/16
to
On Thursday, August 11, 2016 at 3:50:36 PM UTC-7, Russ P. wrote:
> I wrote a program that generates pdf files containing many plots. It can take anywhere from less than a minute to several hours to run. When I run it locally, I want the pdf files to come up automatically. When I run it remotely, however, I don't want the pdf files to come up because the pdf viewer takes ridiculously long to display. In bash, what is the simplest way to determine whether I am running remotely or not? Thanks.

Examining the output of the tty command might be useful.
But what is your idea of "local"?
With tty, you can see if you're on console, or for many *nix flavors,
if you're on a local virtual console. But that's not necessarily
100% test. E.g. if you then use screen(1), you'll get a ptty or the
like. And in that case you may or may not be local ...
in fact with screen(1) you could be both local *and* remote
at the same time(!!!). So, ... does come back to
what is your definition of "local"? And does that include
near by network connection? Or is it more a matter of
speed/throughput of the connection? Maybe you could run
a quick speed check, and decide based upon that, e.g.
use time on some command, and examine the stderr output of
that, and decide based upon that?
0 new messages