- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: who can show my one simple script to get my cu...
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
Discussions
Discussions
Forums
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
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
тАО09-01-2004 04:37 PM
тАО09-01-2004 04:37 PM
I tried like that `who |awk xxx |sed xxx`,but got fail everytime, for I am not the profession to shell script. Who can do me favor for one example?
thanks in advance
Frederick van targero
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2004 05:11 PM
тАО09-01-2004 05:11 PM
Solutionawk 'BEGIN { "/usr/bin/tty" | getline; tty = gensub( /^\/dev\/(.*)$/, "\\1", "g", $0 );print tty;while ( "/usr/bin/who" | getline ) { if ($2 == tty) { hostname = gensub( /\((.*)\)/, "\\1", "g", $NF ); print hostname } } }'
But that does everything. It returns the full-hostname of the current connected tty.
Don't know how it'll behave if it's a console login :P
If you want it to perform some command, you could probably change the 'print hostname' to something like 'system( "your command with argument " hostname )' instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2004 05:14 PM
тАО09-01-2004 05:14 PM
Re: who can show my one simple script to get my current login IP?
awk 'BEGIN { "/usr/bin/who -m" | getline; hostname = gensub( /\((.*)\)/, "\\1", "g", $NF ); print hostname }'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2004 05:21 PM
тАО09-01-2004 05:21 PM
Re: who can show my one simple script to get my current login IP?
who | awk '{ print $6 }' | tr -d '()' | uniq
Where uniq --> It is used to get only uniq ip-address if they did login two or more
Note: IF you are having remote IP-Address which is easily resolvable to hostname then only hostname will be there on who command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2004 06:03 PM
тАО09-01-2004 06:03 PM
Re: who can show my one simple script to get my current login IP?
Change Muthukumar's, to start with 'who -m', and you've got your current tty's details.
Tis much shorter than my awk ;P
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2004 09:24 PM
тАО09-01-2004 09:24 PM
Re: who can show my one simple script to get my current login IP?
We have more problem on who command as,
when ever our IP-Address is resolved by hosts: entry on /etc/nsswitch.conf then,
who command will return hostname not the IP-Address.
If you see who --help for
m --> -m only hostname and user associated with stdin
It will be problem. So we have to change the method as,
IP=$( who -m | awk '{ print $6 }' | tr -d '()')
if [[ $(echo $IP | grep -q '[0-9]*\.[[0-9]*\.[0-9]*\.[0-9]*') -ne 0 ]]
then
let IP_ADDR=$(host $IP | awk '{ print $4 }')
else
let IP_ADDR=$IP
fi
It is done because of getting hostname on who command.
Regards
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2004 12:33 AM
тАО09-02-2004 12:33 AM
Re: who can show my one simple script to get my current login IP?
/sbin/ifconfig eth0|grep inet|awk {'print $2'}|cut -d":" -f2
regards
SK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2004 01:38 AM
тАО09-02-2004 01:38 AM
Re: who can show my one simple script to get my current login IP?
It is not the server's IP-Address.
It is IP-Address of logged user's one.
who -m will give the user shell's login information with the ip-address they started to login to this server.
- Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2004 01:58 AM
тАО09-02-2004 01:58 AM
Re: who can show my one simple script to get my current login IP?
$ echo $REMOTEHOST
192.168.1.7
... the easiest way!
hope your linux distribution sets the same variable. try the 'env' command to look all your environment variables.
ciao
Claudio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2004 11:14 AM
тАО09-02-2004 11:14 AM