Sponsored Content
Top Forums Shell Programming and Scripting Using grep with 'who' to find online users Post 302588200 by frank_rizzo on Saturday 7th of January 2012 01:00:40 PM
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:
 

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
ATF-SH(1)						    BSD General Commands Manual 						 ATF-SH(1)

NAME
atf-sh [-s shell] -- interpreter for shell-based test programs SYNOPSIS
atf-sh script DESCRIPTION
atf-sh is an interpreter that runs the test program given in script after loading the atf-sh(3) library. atf-sh is not a real interpreter though: it is just a wrapper around the system-wide shell defined by ATF_SHELL. atf-sh executes the inter- preter, loads the atf-sh(3) library and then runs the script. You must consider atf-sh to be a POSIX shell by default and thus should not use any non-standard extensions. The following options are available: -s shell Specifies the shell to use instead of the value provided by ATF_SHELL. ENVIRONMENT
ATF_LIBEXECDIR Overrides the builtin directory where atf-sh is located. Should not be overridden other than for testing purposes. ATF_PKGDATADIR Overrides the builtin directory where libatf-sh.subr is located. Should not be overridden other than for testing purposes. ATF_SHELL Path to the system shell to be used in the generated scripts. Scripts must not rely on this variable being set to select a specific interpreter. EXAMPLES
Scripts using atf-sh(3) should start with: #! /usr/bin/env atf-sh Alternatively, if you want to explicitly choose a shell interpreter, you cannot rely on env(1) to find atf-sh. Instead, you have to hardcode the path to atf-sh in the script and then use the -s option afterwards as a single parameter: #! /path/to/bin/atf-sh -s/bin/bash ENVIRONMENT
ATF_SHELL Path to the system shell to be used in the generated scripts. SEE ALSO
atf-sh(3) BSD
September 27, 2014 BSD
All times are GMT -4. The time now is 07:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy