tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* SUMMARY: How to determine local host name in rlogin?
@ 1996-01-18  7:52 Pidgeon, Phillip
  0 siblings, 0 replies; only message in thread
From: Pidgeon, Phillip @ 1996-01-18  7:52 UTC (permalink / raw)
  To: tru64-unix-managers


On 17 Jan 1996, I wrote:
>Hi,
>Does anyone know how to determine the local node name after a rlogin to
>another host. I would like to be able to setenv DISPLAY to the local host
>automatically if possible. Any comments as to methods would be appreciated.

 ----------------------------------------------------------------------------  
 -------------------------------------------------

I selected the following solution for our circumstances:

Given that we use DU csh as default I added the following line to the .cshrc 
file inside
the if ($?prompt) conditional statement. (So errors did not appear on 
dxconsole with no display):

if ($?prompt) then
 .....
 setenv DISPLAY `who -mM | awk '{print substr($6,2,length($6)-2)}'`:0.0
endif

Thanks to all that replied, gives you faith in Human-Kind.......

The mail responses received follow:

 ----------------------------------------------------------------------------  
 -------------------------------------------------
Try

export DISPLAY=`who -mM | awk '{print substr($6,2,length($6)-2)}'`:0.0

Might only work on Digital UNIX though.  Check out who for other options
that might be more compatible with other systems.

Regards,
Jon Buchanan, Zuerich, Switzerland
[ Jonathan.Buchanan@ska.com ]
 ----------------------------------------------------------------------------  
 -------------------------------------------------
Host=`who -M am i | awk 'NF >= 6 {print substr($6,2,length($6)-2);}'`

 ------------------------- ------------------------- -----------------------
| Email: ronwlee@usit.net  |  Phone: (423) 574-6541  |  Fax: (423) 574-7860 
|
 ------------------------- --------- --------------- -----------------------
| Web: http://www.epm.ornl.gov/~re7 | PGP Key: pubkey@re7alpha.epm.ornl.gov 
|
 ----------------------------------- ---------------------------------------
 ----------------------------------------------------------------------------  
 -------------------------------------------------
I think that the w(1) command gives you the info in the "from" field:

osfsable> w
13:12  up 18:24,  2 users,  load average: 0.00, 0.00, 0.00
User     tty        from             login@    idle   JCPU   PCPU what
benoit   p1         sand2             13:11                        w

You just need to grep the username and awk for the 3rd field.

Regards,
        Benoit Maillard
        maillard@fgt.dec.com
 ----------------------------------------------------------------------------  
 -------------------------------------------------
DISPLAY=`hostname`
export DISPLAY

Ross Alexander, ve6pdq  --  (403) 675 6311  --  rwa@cs.athabascau.ca
 ----------------------------------------------------------------------------  
 -------------------------------------------------
It will be done automatically in DU 4.0 if the rlogin comes from a UNIX
computer.

Daniel
o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o
|   Daniel Clar 
                                                                        
 e-mail : Daniel.Clar@supelec.fr  |
|   Computer Operations Manager 
                                                     : dc@supelec.fr 
          |
|   Service Informatique Supelec 
                                                                     and 
                    |
|   Plateau de Moulon 
                                         DECUSF::CLAR_D or clar_d@decus.fr |
|   91192 Gif sur Yvette Cedex - France 
                                                                              
          |
|   Tel : (33 1) 69 85 14 87 
                                                            Fax : (33 1) 69 
85 12 34         |
o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o
 ----------------------------------------------------------------------------  
 -------------------------------------------------
Search archie for xrsh

*** using csh do not have xrsh. Thanks.

Henning Fruechtenicht                  fruechtenicht@rz.fh-wilhelmshaven.de
Rechenzentrum                          Tel.: +49 4421 985323
FH Wilhelmshaven                       Fax.: +49 4421 81950
Friedrich-Paffrath-Str. 101
D-26389 Wilhelmshaven
 ----------------------------------------------------------------------------  
 -------------------------------------------------
One shell, tcsh, does this automatically and sets REMOTEHOST to the
calling machine's hostname. You can find it at tesla.ee.cornell.edu in
/pub/tcsh. GNU bash probably does that too. Both are superior shells
with respect to the standard csh and sh but should _not_ be used for
the root account.

Ciao,

        Arrigo

Arrigo Triulzi <arrigo@lpac.ac.uk>  - +44-171-775-3247
London Parallel Applications Centre - London E1 4NS - UK
 ----------------------------------------------------------------------------  
 -------------------------------------------------
It purely depends on the OS being run on the machine that you are rlogin
in to.  Some systems will display who is logged in from where with the
who(1) command.  You can use `who am i` to obtain this.  On some systems
like SCO v.3, there is no way of detecting this apart from mind-blowing
parsing of the utmp entries, and the netstat listing of socket connections!

Dave Roberts                                | "Just paddling out into big 
surf is a total
Unix Systems Administrator      | commitment" * "You can't just call 
time-out
SAA Consultants Ltd                    | and stroll on back to the beach if 
you don't
Plymouth, UK  <EDI Services> | like the way things are going" - Point Break
 ----------------------------------------------------------------------------  
 -------------------------------------------------
I wrote a little C program which examines the utmp file and prints a
string to set the display variable.
It works for me.

Here is the source:

#include <stdio.h>
#include <utmp.h>
#include <unistd.h>
#include <string.h>


void main(void)
{
    FILE *file;
    char *lname, *ptr, *thetty=NULL;
    struct utmp item;
    int found=0, len;

    lname=getlogin();
    if(lname==NULL || (file=fopen(UTMP_FILE, "rb"))==NULL)
    {
        printf(":0.0\n");
        exit(0);
    }
    len=strlen(lname);
    if(isatty(STDIN_FILENO))
    {
        thetty=ttyname(STDIN_FILENO);
        /* scan for '/' in ttyname */
        if((thetty=strrchr(thetty, '/'))!=NULL)
        {
            thetty++;
        }
    }
    if(thetty==NULL)
    {
        while(fread(&item, sizeof(item), 1, file)==1)
        {
            if(/*item.ut_type==USER_PROCESS &&*/
               strncmp(lname, item.ut_name, len)==0)
            {
                found=1;
                break;
            }
        }

    }
    else
    {
        while(fread(&item, sizeof(item), 1, file)==1)
        {
            if(/*item.ut_type==USER_PROCESS &&*/
               strncmp(lname, item.ut_name, len)==0 &&
               strcmp(thetty, item.ut_line)==0)
               {
                   found=1;
                   break;
               }
        }
    }

    if(found)
    {
        item.ut_host[15]='\0';
        if((ptr=strchr(item.ut_host, ':'))!=NULL)
        {
            *ptr='\0';
        }
        if((ptr=strchr(item.ut_host,'.'))!=NULL)
        {
            *ptr='\0';
        }
        ptr=item.ut_host;
        while(*ptr==' ')
            ptr++;
        printf("%s:0.0\n", ptr);
    }
    else
    {
        printf(":0.0\n");
    }
    fclose(file);
    exit(0);

}


Ciao
           Andreas

**** Thanks for this I'm sure that someone who cannot use my chosen solution 
to work will be greatful for this as I was. Phil P.
+-----------------------------------------------------------------------+
| Dipl.-Ing. Andreas Heckwolf                  Voice :++49 69 798-28359 |
| J.W. Goethe-University                       Fax:   ++49 69 798-23340 |
| P.O. Box 11 19 32                                                     |
| D-60054 Frankfurt                                                     |
+---------- E-Mail : andreas@tm.informatik.uni-frankfurt.de ------------+
 ----------------------------------------------------------------------------  
 -------------------------------------------------

You can use "who -M" or $REMOTEHOST if you have tcsh.

Christophe.


*** I don't have tcsh, but Thanks Phil P.

Christophe DIARRA
I.P.N ORSAY
91406 ORSAY Cedex
Tel: (16 1) 69 41 65 60
E-mail: diarra@ipno.in2p3.fr
 ----------------------------------------------------------------------------  
 -------------------------------------------------
How about the command "hostname"?

*** Not quite this simple I'm afraid, wish it was.
Sho...
Eric R Showalter
 ----------------------------------------------------------------------------  
 -------------------------------------------------

Regards,
Phil Pidgeon
OTIS Engineering Center - Penang, Malaysia
ppidgeon@omc.otis.utc.com

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-01-18  7:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-01-18  7:52 SUMMARY: How to determine local host name in rlogin? Pidgeon, Phillip

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox