IS LOCAL HOSTNAME STORED IN AN ENVIRONMENT VARIABLE

ITEM: RTA000038609



I'm using TCPIP for OS2 v 1.2.1 to telnet to an RS/6000 running AIX             
3.2.3. I begin the connection by executing the tn.exe to host risc01.           
After the login to the system, I would like to automatically start an           
aixterm session. Currently I prompt the user for his local host name,           
and use this name as the -display variable on the aixterm command.              
The problem with this is it is too prone to error. If I do a who                
command from the system console, it shows my login id AND my local              
host name. Is this local host name stored in an environment variable            
available to me to include in a login script which could automatically          
start the aixterm session ?  If so, how do I get to it ?                        
If not, is there some other way to accomplish what I'm trying to do?            
                                                                                
---------- ---------- ---------- --------- ---------- ----------                
A: I will address your questions in the order presented.                        
                                                                               
   1. Is the hostname from who stored in an environment variable?               
                                                                                
      The hostname in the forth column of the 'who' command is the name         
      of the system from which you are connecting.  This name is taken          
      from the "/etc/utmp" database which is updated every time a user          
      logs in or out.  However, the /etc/utmp file is a binary file and         
      thus cannot be easily accessed by shell scripts.                          
                                                                                
      You can set the DISPLAY environment equal to the hostname from the        
      who command using a ksh command similar to the following:                 
                                                                                
      DISPLAY=`who|grep $USER|tail -1|cut -f2 -d"("|cut -f1 -d")"`:0            
                                                                                
      Character Legend:                                                         
         ` = Single Back Quote               | = Pipe (verticle bar)           
                                                                                
      The problem with the above command is that if the user is logged          
      directly into the machine (is not telneting in from another               
      machine), then the DISPLAY variable will be set to their who entry        
      followed by a :0.  For example, if a user 'bob' logged into the           
      console issues the above, their DISPLAY variable will be set to:          
                                                                                
          bob hft/0 Oct 25 08:00 :0                                             
                                                                                
      Another problem with the above command is that it sets the display        
      variable to the name of the machine from which the user is                
      telneting.  This is not always the correct machine to send output         
      to.  For instance, if I am on an X-station named 'maca' with a            
      session on 'macb' and then telnet into 'macc', the above command          
      will set my display variable to 'macb'.  This is not really what         
      is desired; I would prefer my display set to 'maca'.                      
                                                                                
      Therefore, the above command should be used with care.  In response       
      to your second question, I have written a sample script which             
      overcomes these problems at the sacrifice of transparency to the          
      user.                                                                     
                                                                                
   2. Is there another way to accomplish this?                                  
                                                                                
      You may wish to combine the above command with your prompting for         
      in the .profile file.  It will prompt the user for a display              
      variable (displaying the hostname from the who command).  If the          
      user hits , the hostname displayed will be accepted.  If the       
      user enters a valid hostname, it will be accepted.  But, if the           
      an invalid hostname is entered it will not be accepted and the user      
      will be prompted to try again.                                            
                                                                                
      Please note, the sample script below is to be used as an example of       
      how this can be done.  IBM in no way supports this script.                
                                                                                
      Character Legend:                                                         
         ` = Single Back Quote               | = Pipe (vertical bar)            
         . = Open square bracket             . = Close square bracket           
                                                                                
      -------------------------BEGIN SAMPLE SCRIPT-----------------------       
                                                                                
      TDISPLAY=`who|grep $USER|tail -1|cut -f2 -d"("|cut -f1 -d")"`             
      if .. "$TDISPLAY" = "`who | grep $USER | tail -1`" ..                     
      then                                                                      
        TDISPLAY="`hostname`"                                                  
      fi                                                                        
                                                                                
      integer OKAY=1                                                            
      while (($OKAY == 1))                                                      
      do                                                                        
        echo -n "Please enter your display .$TDISPLAY.: "                       
        read VAR                                                                
        if .. "$VAR" = "" ..                                                    
        then                                                                    
                VAR=$TDISPLAY                                                   
        fi                                                                      
                                                                                
        if .. "`host $VAR 2> /dev/null | cut -f1 -d:`" ¢= "" ..                 
        then                                                                    
                OKAY=0                                                         
        fi                                                                      
      done                                                                      
      export DISPLAY=$VAR:0                                                     
                                                                                
      -------------------------END SAMPLE SCRIPT-------------------------       
                                                                                
   To summarize, the 'who' command is obtaining the hostname from which         
   the user is logging in from the /etc/utmp database.  Information about       
   the user is placed in this database when the user logs in.  Although         
   the /etc/utmp file is in a binary format, the hostname from which the        
   user logs in can be obtained by parsing the output of the who command.       
   This does have problems, though, since it only displays which machine        
   the user is logging in from and not necessarily the correct machine          
   to send X output to.  By integrating the output from this command with       
   your existing method of prompting for a display name, as well as            
   verifying that a valid hostname was entered, the result is a fairly          
   robust and user friendly system by which the DISPLAY variable is             
   automatically setup.                                                         
                                                                                
   Note: With the DISPLAY variable set, it is not necessary to use the          
   "-display" flag as aixterm will read the DISPLAY variable by default.        
                                                                                
   One general note on AIX Technical Support policy: unfortunately we           
   cannot write scripts for you, but somethimes we can provide sample           
   scripts or ideas on how to write a script.  When a sample script is          
   provided, that script is purely an example of how something can be           
   done and the script is not supported by IBM.                                 
                                                                                
---------- ---------- ---------- --------- ---------- ----------                
                                                                               
                                                                                
This item was created from library item Q652306      9SBLF                      
                                                                                
Additional search words:                                                        
ARISC CUSTORG ENVIRONMENT HOSTNAME IX JAN94 LOCAL OS2 OZNEW RISC SET            
SETTING TCPIP VARI X-WINDOWS XWINDOWS 9SBLF                                     
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                               


WWQA: ITEM: RTA000038609 ITEM: RTA000038609
Dated: 11/1996 Category: RISCOSO
This HTML file was generated 99/06/24~12:43:15
Comments or suggestions? Contact us