#! /bin/bash
- ########################################
NAME_="loggedin"
PURPOSE_="notify when a particular user has logged in"
SYNOPSIS_="$NAME_ [-hml] <user> <n>"
REQUIRES_="standard GNU commands"
VERSION_="1.1"
DATE_="2000-10-07; last update: 2004-04-21"
AUTHOR_="Dawid Michalczyk <
dm@eonworks.com>"
URL_="www.comp.eonworks.com"
CATEGORY_="misc"
PLATFORM_="Linux"
SHELL_="bash"
DISTRIBUTE_="yes"
- #########################################
- This program is distributed under the terms of the GNU General Public License
usage () {
echo >&2 "$NAME_ $VERSION_ - $PURPOSE_
Usage: $SYNOPSIS_
Requires: $REQUIRES_
Options:
<user>, user name
<n>, integer referring to seconds
-h, usage and options (this help)
-m, manual
-l, see this script"
exit 2
}
manual () { echo >&2 "
NAME
$NAME_ $VERSION_ - $PURPOSE_
SYNOPSIS
$SYNOPSIS_
DESCRIPTION
$NAME_ displays a notification message when a particular user has logged in.
The user option specifies the user name of the person and the time option is
the time interval, in seconds, for how often to check whether the user has
logged in.
"; exit 2; }
loggedin() {
# checking if user is logged out
who | grep "^$1 " 2>&1 > /dev/null
if [[ $? == 0 ]]; then
echo user $1 is logged in
exit 1
fi
# checking when user logs in
until who | grep "^$1 "; do
sleep $2
done
echo $1 just logged in
exit 0
}
- arg check
[ $# -eq 0 ] && { echo >&2 missing argument, type $NAME_ -h for help; exit 2; }
case $1 in
-h) usage;;
-m) manual ;;
-l) more $0; exit 2 ;;
*) [ $# -eq 2 ] && loggedin $1 $2 || { echo invalid argument use, type $NAME_ -h for help; exit 2; }
esac