Showing offline users


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Showing offline users
# 1  
Old 04-28-2009
Showing offline users

Hi,

Is there any command for showing offline users?

The only way I can think of doing it (as i cant find a command) is getting a list of all the online users, and comparing it to /etc/passwd, anything that is in /etc/passwd and not in the users file will be offline users. But I have no knowledge of how to implement this.

I have a file called ./users that contains code:

Code:
echo "The current users logged in are:" && who | awk '{ p
rint $1 }' | sort -u

Any help appreciated.

Thanks Smilie
# 2  
Old 04-28-2009
You didn't specify what exactly is your OS, which may have a way to display those that are offline. At first glance I can think of the following (ugly, but it works) :
Code:
cat /etc/passwd | cut -d":" -f1 | egrep -v '(avahi|beagleindex|messagebus|news|ntp)' > allusers
# this line will cat /etc/passwd and will print the user names as in : 
user1
user2
etc... 
# Inside the parentheses there is a list of user names to be omitted - the system ones, like in my case : news, ntp, games, mail, etc. 
#You will need to modify that per your case. Then the output is being redirected to a file. 
# Here you can execute your piece of code : 
who | awk '{ print $1 }' | sort -u >> allusers
# This will print the list of active users, and will append this list to the original file, containing all users. 
#  Then, we use 'uniq -u' to print only the unique ones - meaning, those that aren't online. 
uniq -u allusers
# the list follows. HTH.

# 3  
Old 04-28-2009
Another approach:

Code:
awk 'BEGIN{while("who"|getline)a[$1]}
!($1 in a){print $1}' FS=":" /etc/passwd

Use nawk or /usr/xpg4/bin/awk on Solaris.
# 4  
Old 04-28-2009
Yet an another approach:::

Code:
$ who | awk '{print $1}' >>file
 
$ egrep -vf file /etc/passwd | awk -F":" '($3 >= 500 && $3 < 65534) {print $1 }'

The condition inside the awk should be changed depending on the OS you use.
# 5  
Old 04-28-2009
thanks guys,

All methods work. Thanks for the idea of getting rid of all the system users, never thought of that!!

Cheers!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Drive is showing offline in the /var/adm/messages and shows "drive type unknown" in the format outpu

Hi, I am facing issue with one of the drive is solaris 10. it is showing offline in the messages file scsi: WARNING: /pci@2,600000/QLGC,qlc@0/fp@0,0/ssd@w5006016746e00b1b,0 (ssd0): drive offline genunix: WARNING: Page83 data not standards compliant DGC LUNZ 0430 ... (1 Reply)
Discussion started by: Prasanth T K
1 Replies

2. HP-UX

After adding new iscsi target port, still the session state of that target port is showing offline

Hi, I wanted to configure new iscsi port on HPUX system, i added the target port address and configured it, once done, went to array side and searched for that host iqn number , but was nt able to find the same, came to host, then when i ran "iscsiutil -pVS" command it gave me below result ... (0 Replies)
Discussion started by: Vinay Kumar D
0 Replies

3. Red Hat

Showing all users in 'users' and 'top' commands

Hi All, I work in a multi user environment where my school uses Red Hat Linux server. When I issue commands such as "top" or "users", I get to see what others are doing and what kinds of applications they are running (even ps -aux will give such information). "users" will let me know who else is... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

4. UNIX for Dummies Questions & Answers

Need help showing which network protocol users use.

I'm having a bit of a trouble trying to figure out how to tell which network protocol users HAVE been logging in with. I know how to find this information for currently logged in users : maximillian.gardner@syccuxfs01:~> who joseph.blosser pts/0 2012-01-15 14:07 (198.107.160.185)... (5 Replies)
Discussion started by: maximillian.g
5 Replies

5. UNIX for Dummies Questions & Answers

Offline Agents Inquiry.

Hello, I currently use Solaris, and typically I use the svcs -a | grep PROCESS to see if it's online or Offline. My questions is SVCS is in solaris but if I want to find out if a daemon or process is offline what other methods can I use? ps -ef | grep PROCESS "what do I look for" or... (1 Reply)
Discussion started by: NelsonC
1 Replies

6. Shell Programming and Scripting

bash script for showing last users

Hi! I'm new in scripting and I need some help with one simple script. I have to write a program that shows in a predetermined period (using "last" command), to draw up a list of users who have used the machine during this period. Each user to indicate how many sessions it has been during this... (9 Replies)
Discussion started by: vassu
9 Replies

7. Solaris

Offline HBA.

Hi, I have a HBA that is currently offline for some unknown reason. The device shows up in the prtdiag -v stating it is okay. How can I bring this back online? It was working okay until recently. It is currently connected to the SAN. Details below. # fcinfo hba-port HBA Port WWN:... (7 Replies)
Discussion started by: sparcman
7 Replies

8. Solaris

How to keep volumes offline after reboot

Hi All, How to keep the volumes offline after reboot also, i make it offline like below # metaoffline d0 d20 after reboot its automatically getting online, however i have to keep it offline and as on required i have to make it online as per business. Thanks in anticipation (9 Replies)
Discussion started by: kumarmani
9 Replies

9. IP Networking

HELP!! NICs went offline suddenly

I have a new server... We were doing some testing on it over the local ethernet. All was well in the night when we turned off the machine. In the morning we were unable to get the server online. Have changed cables, NICs, looked over network settings... all to no avail. I am running Redhat... (4 Replies)
Discussion started by: skotapal
4 Replies
Login or Register to Ask a Question