- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Scripting Challenge
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 01:51 AM
11-06-2003 01:51 AM
I have a scripting problem that I can't quite get solved.
We have an MC/SG environment and I need a script that I can run when users log in that will somehow determine the MC/SG package they are telnet'ing and based on the package set some environment variables for their session.
I have written a script that generally works, but the problem I am having is that this must also work if a user uses 'su' to switch to a different user.
Any and all suggestions welcome!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 02:03 AM
11-06-2003 02:03 AM
Re: Scripting Challenge
It was all going so well until your last sentence. It must work with "su". I take you mean that we can't guarantee .profile is going to get run?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 02:07 AM
11-06-2003 02:07 AM
Re: Scripting Challenge
i thing you try "su user", if yes try the following:
su - user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 02:08 AM
11-06-2003 02:08 AM
Re: Scripting Challenge
How about replacing "su" with a script that invokes the real "su" - with the - option?
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 02:09 AM
11-06-2003 02:09 AM
Re: Scripting Challenge
Are you trying to figure out who is the user originally ?
whoami vs who am i ?
Rgds,
JL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 02:10 AM
11-06-2003 02:10 AM
Solutionpid=$(ps -t$(tty |sed 's|/dev/||') | grep telnetd | awk '{print $1}')
[ -n "$pid" ] && lsof -p $pid | grep TCP | sed 's|^.*>\(.*\):.*$|\1|' | uniq
But with the su, I, not sure I understand what you want. If you want the same effect as with the telnetting, it would work here to.
Another way, which we use, is give users a homedirectory in the package. Then it is easy to do. But this only works if a user is package specific. Which is apparently not your case.
Hope this helps you solve the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 02:11 AM
11-06-2003 02:11 AM
Re: Scripting Challenge
# ps -t `basename \`tty\`` -ouser
USER
root
cw16791n
root
If more than 2 entries are returned, you know that it's the USER header, the original id and any su id.
Chris.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 02:12 AM
11-06-2003 02:12 AM
Re: Scripting Challenge
My big problem, even with 'su - user' is how do you tell what package name / IP they connected to originally?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 02:12 AM
11-06-2003 02:12 AM
Re: Scripting Challenge
e.g.
$id
uid=222(dba) gid=201(...)
$ su informix
Password:
$ echo $LOGNAME
dba
$ echo `logname`
dba
$ exit
$ su - informix
Password:
...
$ echo $LOGNAME
dba
$ echo `logname`
dba
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 02:13 AM
11-06-2003 02:13 AM
Re: Scripting Challenge
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 02:35 AM
11-06-2003 02:35 AM
Re: Scripting Challenge
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 02:49 AM
11-06-2003 02:49 AM
Re: Scripting Challenge
You can track the PID of the login shell that issued the "su - someone" by putting something like this in .profile
ORIG_SHELL=$(UNIX95= ps -o ppid= -p $$)
With this PID you could further track the associated pseudo terminal an try to match with output from "who -u".
If you have lsof on the box I guess you could even track down the sockets used by the telnetd that served the login which uses the pty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 02:55 AM
11-06-2003 02:55 AM
Re: Scripting Challenge
At least you could narrow possible telnet sockets by parsing netstat with something like
# netstat -anfinet|awk '$4~/\.23$/{print$5}'
will list foreign IPs of telnet sockets.
The least we know is the port they connected trhough.
netstat also give the local IPs which are the 4th column and should correspond to your MC/SG packages' IPs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 03:20 AM
11-06-2003 03:20 AM
Re: Scripting Challenge
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 03:42 AM
11-06-2003 03:42 AM
Re: Scripting Challenge
I wound up doing this to get the package name the user telnet'ed to (and this still worked when the user did a 'su - username' to switch user):
PID=$(ps -t $(tty |sed 's|/dev/||') | grep telnetd | awk '{print $1}')
TOPACKAGE=$([ -n "$PID" ] && /usr/local/bin/lsof -p $PID | grep TCP | awk '{print $9}' | awk -F : '{print $1}' | awk -F . '{print $1}' | uniq)
The last 3 awk statements is my crude way of getting the name of the package (without the domain name) the user telnet'ed to. I'm sure there is a better way to do it, but this works for me.
Man I LOVE these forums.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 05:05 PM
11-06-2003 05:05 PM
Re: Scripting Challenge
I was thinking about calling someone to put it right (and score some points) but thought you would be able to do this too.
Happy it solved your problem.