The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sorting your data with msort iBot UNIX and Linux RSS News 0 05-19-2008 12:20 PM
Sorting data and place them in different folders Vinaykumar1 UNIX for Dummies Questions & Answers 29 05-14-2008 09:47 AM
sorting data using array in ksh ali560045 Shell Programming and Scripting 4 12-04-2007 04:26 AM
Sorting blocks of data alfredo123 Shell Programming and Scripting 8 07-05-2007 11:53 AM
Newbie Awk data sorting i_am_a_robot Shell Programming and Scripting 5 05-04-2007 08:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-16-2008
raidzero's Avatar
raidzero raidzero is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 60
sorting data from who by IP

Hello. I have an RS/6000 running AIX 4 and I need to be able to see if there are any users that are logged on more than once from the same terminal so I can kick them off to make room for other terminals. 64 connections is the limit. Currently I am doing this:

who | more
and then manually looking for duplicate IP's and then doing
ps -t pts/whatever or tty
to find the PID then killing the PID. Is there an easier and faster way of doing this? Thanks

-paul
  #2 (permalink)  
Old 06-16-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 753
Instead of manually looking for duplicate IDs you can pipe the output to sort for getting unique records...


Code:
who | sort -uk6.2,6

  #3 (permalink)  
Old 06-16-2008
raidzero's Avatar
raidzero raidzero is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 60
Thanks - but that is not showing me duplicates, instead it looks like there are no duplicates. I just tested by opening up two more connections from my machine and ran that command.
  #4 (permalink)  
Old 06-16-2008
raidzero's Avatar
raidzero raidzero is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 60
By removing the U, so it is just
who | sort -k6.2,6

it works. Thanks again
  #5 (permalink)  
Old 06-16-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Question Can you show a sample command and output?

It can sometimes be difficult to "imagine" what your output looks like. Thus, examples are always a good way to convey the requirments.

Does this code:

Code:
who | tr -s " " | cut -d" " -f1,6 | sort | uniq -c

provide you with
count username ip_address?
If so, it may be the start of your process.

Last edited by joeyg; 06-16-2008 at 01:03 PM.. Reason: added sample code line
  #6 (permalink)  
Old 06-16-2008
raidzero's Avatar
raidzero raidzero is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 60
Here is a snippet of who | sort -uk6.2,6 :

# who | sort -uk6.2,6
bhb tty11 Jun 16 11:06
rf1 pts/67 Jun 16 10:21 (10.203.32.105)
rf1 pts/20 Jun 16 10:58 (10.203.32.109)
bhb pts/4 Jun 16 06:24 (10.203.32.110)
rf1 pts/28 Jun 16 09:54 (10.203.32.117)
bhb pts/63 Jun 16 09:00 (10.203.32.123)
rf1 pts/9 Jun 16 09:42 (10.203.32.124)
bhb pts/50 Jun 16 09:26 (10.203.32.126)
root pts/54 Jun 16 08:30 (10.203.32.132)
bhb pts/25 Jun 16 07:21 (10.203.32.151)
bhb pts/10 Jun 16 10:49 (10.203.32.152)
bhb pts/35 Jun 16 07:40 (10.203.32.157)
bhb pts/2 Jun 16 10:47 (10.203.32.159)
bhb pts/23 Jun 16 07:20 (10.203.32.163)
bhb pts/26 Jun 16 07:22 (10.203.32.171)
bhb pts/1 Jun 16 06:26 (10.203.32.172)
bhb pts/41 Jun 16 07:53 (10.203.32.173)
bhb pts/27 Jun 16 11:13 (10.203.32.183)
bhb pts/21 Jun 16 10:28 (10.236.1.131)
bhb pts/24 Jun 16 11:54 (10.236.32.93)
bhb pts/42 Jun 16 09:24 (10.238.0.148)
bhb pts/39 Jun 16 07:52 (10.238.1.29)
bhb pts/31 Jun 16 10:34 (10.238.1.42)

here is a snippet of who | sort -k6.2,6 :

# who | sort -k6.2,6
bhb tty11 Jun 16 11:06
bhb tty14 Jun 16 09:44
bhb tty17 Jun 16 09:47
bhb tty37 Jun 16 08:25
bhb tty49 Jun 16 09:21
bhb tty8 Jun 16 07:54
root tty1 Jun 16 08:18
rf1 pts/67 Jun 16 10:21 (10.203.32.105)
rf1 pts/20 Jun 16 10:58 (10.203.32.109)
bhb pts/4 Jun 16 06:24 (10.203.32.110)
rf1 pts/28 Jun 16 09:54 (10.203.32.117)
bhb pts/63 Jun 16 09:00 (10.203.32.123)
rf1 pts/9 Jun 16 09:42 (10.203.32.124)
bhb pts/50 Jun 16 09:26 (10.203.32.126)
root pts/54 Jun 16 08:30 (10.203.32.132)
bhb pts/25 Jun 16 07:21 (10.203.32.151)
bhb pts/10 Jun 16 10:49 (10.203.32.152)
bhb pts/35 Jun 16 07:40 (10.203.32.157)
bhb pts/2 Jun 16 10:47 (10.203.32.159)
bhb pts/23 Jun 16 07:20 (10.203.32.163)
bhb pts/26 Jun 16 07:22 (10.203.32.171)
bhb pts/1 Jun 16 06:26 (10.203.32.172)
bhb pts/41 Jun 16 07:53 (10.203.32.173)

(un)fortunately, I have killed all the duplicate sessions, so none are showing up in my examples. To get really lazy, is there a way to ONLY show the duplicate IPs?
  #7 (permalink)  
Old 06-16-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 753
Quote:
Originally Posted by raidzero View Post
To get really lazy, is there a way to ONLY show the duplicate IPs?


Code:
who | \
sort -k6.2 | \
awk '{
  if (x[$6]++) {
    if (prev)
       printf("%-8s %s\n", prev, $6)
    printf("%-8s %s\n", $2, $6)
    prev=""
  } else
    prev = $2
}'

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0