Sponsored Content
Top Forums Shell Programming and Scripting Using grep with 'who' to find online users Post 302588199 by ahamed101 on Saturday 7th of January 2012 12:55:49 PM
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 More Discussions You Might Find Interesting

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

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. 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
ZGREP(1)                                                      General Commands Manual                                                     ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 01:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy