<<< Date Index >>>     <<< Thread Index >>>

Re: text/html; mutt_bgrun mozilla.sh %s; test=InXTerm



On Fri, Nov 04, 2005 at 10:23:41AM +0000, Chris Green wrote:
> > Better still, define and use your own environment variable expressly
> > for this purpose.  Even if DISPLAY is set, you may not want to launch
> > your web browser...  An example would be if you're logged in remotely
> > over 300 bps modem.  :)  I think I even still have one of those in a box
> > somewhere...
> > 
> ... but how would you provide logic to set this variable?

It's not as hard as you think.  You can find out which TTY your
session is using quite easily:

  $ tty
  /dev/pts/0

Now you can use that to find out if you're logged in locally or
remotely:

  $ w
   12:00:46 up 17 min,  4 users,  load average: 0.00, 0.13, 0.15
  USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
  foo      :0       -                11:52   ?xdm?  21.62s  0.19s /bin/bash 
  foo      pts/0    -                11:52    0.00s  0.05s  0.00s w
  foo      pts/1    -                11:52    4.00s  0.21s  0.17s ssh thoth
  foo      pts/2    -                11:52    8:02   0.04s  0.04s -bash
  
if the FROM column contains '-' then it's a local login, or if it
contains a hostname or an IP address (which doesn't match the local
one), then it's obviously a remote connection.  So you could test for
that.

Of course, ssh also sets various environment variables:

  $ env |grep -i ssh |cut -d'=' -f 1
  SSH_CLIENT
  SSH_TTY
  SSH_ASKPASS
  SSH_CONNECTION

You could test for these...  But the method I suggested first might be
preferable, because you may want to set the variable if you've logged
into the local host via ssh (this is one way to log in as a different
user to the same host, for example)...  The latter method is certainly
easier.  That's up to you.  ;-)

> I suppose I could detect the ssh environment variables but that is a
> bit messy/indirect.

Well, I don't really see that, but I provided an alternative. :)

-- 
Derek D. Martin    http://www.pizzashack.org/   GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address.  Replying to it will result in
undeliverable mail.  Sorry for the inconvenience.  Thank the spammers.

Attachment: pgpIEH3kS4vif.pgp
Description: PGP signature