1834022 Members
2433 Online
110063 Solutions
New Discussion

MC Package Name

 
SOLVED
Go to solution
Smirjit Singh
Advisor

MC Package Name

Hi All,

Is it possible to know which user has loged in which package of MC/Service Guard ? Actually we have one cluster. 4 nodes is attached with that cluster. Now generally our user logs in by making telnet . So actually physically they logs in different node. But if I want to execute some command which will act according to package name. Then how I can execute. Becs hostname will return node name.

Is their anyway to know package name where user has logged in ?
Knowledge is only most valuable things which can't buy.
4 REPLIES 4
Santosh Nair_1
Honored Contributor

Re: MC Package Name

Sandip,

One way that occured to me was to use the lsof command on the parent telnetd process, something like of -p $PPID|grep TCP. One of the field in this is the ip/hostname that established the telnet session.

I'm sure there are better ways, but this is what I came up with off the top off my head.

-Santosh
Life is what's happening while you're busy making other plans
linuxfan
Honored Contributor
Solution

Re: MC Package Name

Hi Sandip,

You could do something like this,

Create a file called /etc/checkhost

/Begin/
#!/sbin/sh
trap "" 1 2 3

PATH=/usr/bin:/sbin:/usr/local/bin
UID=$(/usr/bin/id -u)

who -mu | awk '{print $2, $NF}' | while read TTY host
do
MYPID=`ps -ef |egrep " $PPID "|egrep -v "$$|egrep" | awk '{print $2}'`

TO_HOST=`lsof -p $MYPID | egrep ":telnet|:login" |head -1 | awk '{print $9}'|cut -d: -f1`

echo "##################################"
echo "You logged in to host $TO_HOST"
# You can do additional commands here based on the static or relocatable host
echo "########################"
sleep 4
done

/End/


Also modify your /etc/profile to include

/Begin/
if [ -f /etc/checkhost ]
then
. /etc/checkhost
fi
/End/
-HTH
Ramesh
They think they know but don't. At least I know I don't know - Socrates
Santosh Nair_1
Honored Contributor

Re: MC Package Name

Just thought of another way to get this information...

Get the hostname where the user came from using last -R -1 $LOGNAME. Then use netstat -a |grep
to get the IP address that they telneted to.

---snip---
FRM_HOST=$(last -R -1 snair|awk '{print $3}'|cut -f 1 -d.)
TO_HOST=$(netstat -a|grep $FRM_HOST|awk '{print $4'}|cut -f 1 -d.)

Code can probably be cleaned up a lot, but basically this is how it would work.

-Santosh
Life is what's happening while you're busy making other plans
Sanjay_6
Honored Contributor

Re: MC Package Name

Hi,

If you have logging enabled for telnet in /etc/services , then i think you can find this info from /var/adm/syslog/syslog.log. Just a thought.

Hope this helps.

Thanks