Using grep with 'who' to find online users


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using grep with 'who' to find online users
# 1  
Old 01-07-2012
Using grep with 'who' to find online users

solved

Last edited by subway69; 01-09-2012 at 02:23 PM..
# 2  
Old 01-07-2012
Code:
who | grep -w ^$user >/dev/null 2>&1
if [ $? -eq 0 ]
then
  echo "$user is online"
else
  echo "$user not online"
fi

if your grep supports -q option, use it like this who | grep -qw "^$user"

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 01-07-2012
even more streamlined.

Code:
if who|grep -qw ^$user >/dev/null 2>&1
then
  echo "$user is online"
else
  echo "$user not online"
fi

or the one line version.

Code:
who|grep -qw ^$user && echo "$user online" || echo "$user not online"


Last edited by frank_rizzo; 01-07-2012 at 02:11 PM.. Reason: added one line
This User Gave Thanks to frank_rizzo For This Post:
# 4  
Old 01-07-2012
gah I should have known to pipe grep I completely forgot

still learning. . .

thanks guysSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. AIX

Savevg when users online !!

Hi All, I need to take the backup of non-rootvg using savevg utility. I would like to know, if I can take the backup without shutting down the application & database. Is it possible to take the savevg backup safely when users are working on the system ? Regards. (1 Reply)
Discussion started by: sraj142
1 Replies

2. Shell Programming and Scripting

find top 4 users currently logged on can i use grep

For the first 4 users only that are currently logged in output their effective user id. It's not important the order in which each logged in i just want to have the top 4. Same question as here...... (0 Replies)
Discussion started by: whyatepies
0 Replies

3. Shell Programming and Scripting

Get online users OpenSuse

Hello, is there any Shell Command to get a list of all the online users currently online and logged in on my machine? finger and who both show a log of people that logged in, not the ones that are currently online. (3 Replies)
Discussion started by: Aliboy
3 Replies
Login or Register to Ask a Question