Operating System - HP-UX
1827197 Members
2309 Online
109716 Solutions
New Discussion

How to configure $REMOTEHOST env variable ?

 
SOLVED
Go to solution
J Ramesh Kumar
Advisor

How to configure $REMOTEHOST env variable ?

Hi,

By default my HP UX m/c doesn't configure $REMOTEHOST variable. How can I configure REMOTEHOST variable ? Pls help me.

Thanks,
Ramesh

19 REPLIES 19
Pete Randall
Outstanding Contributor

Re: How to configure $REMOTEHOST env variable ?

I'm afraid we need more details of what you are trying to accomplish and what you expect this variable to contain before we can be of much help.


Pete

Pete
Yogeeraj_1
Honored Contributor

Re: How to configure $REMOTEHOST env variable ?

hi,

Pete is right! Unless, you know what this variable meaning is, you cannot define it.

If you want to explicitly define this variable, you must execute the following commands:
REMOTEHOST=
export REMOTEHOST


You may also wish to include this in your .profile or /etc/profile


hope this helps!
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
J Ramesh Kumar
Advisor

Re: How to configure $REMOTEHOST env variable ?

Hi,

Sorry for insufficient information.

By default, the $REMOTEHOST env variable is set in the linux env. The $REMOTEHOST variable has the name of the remote host which connected to a linux m/c.

I am trying to get name of the remote m/c which connected to a hpux m/c.This will help to monitor the remote host activities. Hope this clear.

Thanks,
Ramesh
J Ramesh Kumar
Advisor

Re: How to configure $REMOTEHOST env variable ?

Hi,

Sorry for the insufficient information.

By default, the $REMOTEHOST env variable is set in the linux env. The $REMOTEHOST variable has the name of the remote host which connected to a linux m/c.

I am trying to get name of the remote m/c which connected to a hpux m/c.This will help to monitor the remote host activities. Hope this clear.

Thanks,
Ramesh
Dennis Handly
Acclaimed Contributor

Re: How to configure $REMOTEHOST env variable ?

>I am trying to get name of the remote m/c which connected to a hpux m/c.

Something like:
who -a | awk -v user=$LOGNAME '$0 ~ user {print $NF}'
James R. Ferguson
Acclaimed Contributor

Re: How to configure $REMOTEHOST env variable ?

Hi Ramesh:

> Dennis: who -a | awk -v user=$LOGNAME '$0 ~ user {print $NF}'

I think Dennis meant 'who -u' as:

# who -u | awk -v user=$LOGNAME '$0 ~ user {print $NF}'

Regards!

...JRF...
J Ramesh Kumar
Advisor

Re: How to configure $REMOTEHOST env variable ?

Hi Dennis / JRF,

Thanks for the response. The following command gives all the m/c names which are currently connected.

who -u | awk -v user=$LOGNAME '$0 ~ user {print $NF}'

But I require the remote m/c name of the current terminal/telnet. I do not require all the remote host names. I am currently working on monitoring of user activities. Please refer the following thread for complete details about the functionality. And also please search REMOTEHOST string in the attachment of that thread. I need to set the exact m/c name into that variable.

http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1232079


Thanks,
Ramesh
Dennis Handly
Acclaimed Contributor
Solution

Re: How to configure $REMOTEHOST env variable ?

>The following command gives all the m/c names which are currently connected.

Yes, for that user.

>But I require the remote m/c name of the current terminal/telnet.

Ok, you can use this script:
#!/usr/bin/ksh
# Find source machine from tty(1)
TTY=$(tty) # issue with pipes
who -u | awk -v tty=$TTY '
BEGIN { tty = substr(tty, 6) } # strip /dev/
$0 ~ tty {print $NF}'
J Ramesh Kumar
Advisor

Re: How to configure $REMOTEHOST env variable ?

Hi Dennis,

The script does not give any output. I have saved the script commands in a file named a.sh and I executed it by "$sh a.sh". It does not print anything in the console. Am I miss anything ?

Thanks,
Ramesh
J Ramesh Kumar
Advisor

Re: How to configure $REMOTEHOST env variable ?

Hi Dennis,

For your quick reference, my console output of "who -u" command is,

bash-3.00$ who -u
test pts/ta May 1 18:15 . 15226 MEPS1.india.adventnet.com
test pts/tb May 16 15:16 21:10 22735 rameshj.india.adventnet.com
test pts/tc May 17 11:36 0:04 12941 rameshj.india.adventnet.com
test pts/td May 15 15:06 0:09 23817 opman-sigma1.india.adventnet.com
guest pts/0 May 17 10:41 old 11028 assetmgmt-test1.india.adventnet.com
test pts/te May 17 12:23 . 14597 rameshj.india.adventnet.com
test pts/tf May 16 16:35 19:53 26126 rameshj.india.adventnet.com
guest pts/1 Apr 29 01:41 old 20391 console-server.india.adventnet.com
guest pts/2 Apr 29 01:41 old 20402 console-server.india.adventnet.com

My HPUX version is, B.11.11

This may help you to identify the issue.

Thanks,
Ramesh
Dennis Handly
Acclaimed Contributor

Re: How to configure $REMOTEHOST env variable ?

>The script does not give any output.

It worked fine for me, after a lot of tweaking. :-)

>I executed it by "$sh a.sh". It does not print anything in the console. Am I miss anything?

That should be it. But you could make it executable so you don't need to use "sh".

Add this echo here:
TTY=$(tty) # issue with pipes
echo "TTY is: $TTY"
J Ramesh Kumar
Advisor

Re: How to configure $REMOTEHOST env variable ?

Hi Dennis,

After adding the echo the script output is,

bash-3.00$ ./a.sh
TTY is: /dev/ttyp6
bash-3.00$

I could not find any information related to tty in the who -u command output. This may be configuration issue. But I am sure.

Thanks,
Ramesh
Dennis Handly
Acclaimed Contributor

Re: How to configure $REMOTEHOST env variable ?

>For your quick reference, my console output of "who -u" command is,

Thanks. I don't see your tty there.

>I could not find any information related to tty in the who -u command output.

It talks about "line". There is also mention about using -R with -u but I don't see much difference.

What do you get for: pty
And: ll -i /dev/ttyp6
J Ramesh Kumar
Advisor

Re: How to configure $REMOTEHOST env variable ?

Hi Dennis,

Following are the output of the required commands,

bash-3.00$ pty
/dev/ttyp6
bash-3.00$ ll -i /dev/ttyp6
822 crw--w---- 2 test tty 17 0x000006 May 17 14:55 /dev/ttyp6
bash-3.00$

Thanks,
Ramesh
Dennis Handly
Acclaimed Contributor

Re: How to configure $REMOTEHOST env variable ?

>Following are the output of the required commands
>$ ll -i /dev/ttyp6
822 crw--w---- 2 test tty 17 0x000006 May 17 14:55 /dev/ttyp6

Perhaps there are two names for this tty? How about:
$ find /dev -inum 822

(On my system the basenames of the files match.)
J Ramesh Kumar
Advisor

Re: How to configure $REMOTEHOST env variable ?

Following are the output of find command,

# find /dev -inum 822
/dev/pty/ttyp6
/dev/ttyp6
#
Dennis Handly
Acclaimed Contributor

Re: How to configure $REMOTEHOST env variable ?

>Following are the output of find command,
>/dev/pty/ttyp6 /dev/ttyp6

Hmm, I'm not sure how to map these BSD pseudo terminals to your Streams pseudo-terminals.
Looking at pts(7) ptm(7) pty(7) doesn't mention it.

You might be able to map the time stamp on ttyp6 with one in the /dev/pts/ directory???
J Ramesh Kumar
Advisor

Re: How to configure $REMOTEHOST env variable ?

Hi,

If the script suggested by you is working fine for most of the HP UX system, I may go with that script. In case of any issue in finding remote host(like my local HP UX m/c), my application log will be reported as "Unknown Host". But I would like convert your script into 2 lines and assign the host name into a variable named REMOTEHOST. Is the following 2 lines working fine in ur m/c ? ie, the REMOTEHOST variable is properly assigned with actual value. This will help me integrate the same.

TTY=$(tty) # issue with pipes
REMOTEHOST=`who -u | awk -v tty=$TTY 'BEGIN { tty = substr(tty, 6) } $0 ~ tty {print $NF}'`

Since the issue in my m/c may be due to configuration issue, we will try to identify the issue in parallel.

I really appreciate your great support and effort on resolving the issue. Thank you very much.

Thanks,
Ramesh
Dennis Handly
Acclaimed Contributor

Re: How to configure $REMOTEHOST env variable ?

>Is the following 2 lines working fine in your m/c? ie, the REMOTEHOST variable is properly assigned with actual value.

Yes. But you shouldn't use the obsolete ``.
Use this one liner:
REMOTEHOST=$(TTY=$(tty); who -u | awk -v tty=$TTY 'BEGIN { tty = substr(tty, 6) } $0 ~ tty {print $NF}')

Note you don't really need to put this all on one line. You can do:
REMOTEHOST=$(TTY=$(tty)
who -u |
awk -v tty=$TTY '
BEGIN { tty = substr(tty, 6) }
$0 ~ tty {print $NF}')