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:

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

Any help appreciated.

Thanks :o

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) :

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.

Another approach:

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

Use nawk or /usr/xpg4/bin/awk on Solaris.

Yet an another approach:::

$ 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.

thanks guys,

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

Cheers!