RE: notification of user login
Looking for a way to get a notification when a user logs in via email?
The only why I have been able to think of was to move /bin/sh and
/bin/bash and create bash files to load these along with sending a
email. But I was wondering if there is a easier way ? Or a program
designed for this ?
Not sure if this is quite what you're after, but it can be adapted. I
sometimes want to check
on a particular user as a one-time thing ... usually I want to know when
they've seen their e-mail,
or sometimes just when they're back at their desk. These are people who
don't log in except via
imap, so I'm not looking for shell logins, but the approach will work for
that too. Basically it's
just a script that repeatedly uses "finger" until the results change. (I
have the finger service
running, but configured so that it only responds to requests coming from
To make it look for a shell login, just change the patterns it's looking for
in the grep statements.
The advantage over the method you suggest is that this doesn't require
making any changes
to the person's login scripts, so you can use it for anyone any time. If
you want to know every
time they log in, it's not really suited for that, because it exits when
they log in.
--------shell script begins (beware of lines that got wrapped in the e-mail)
echo "Usage: $0 [-ms] user [wait-secs]"
echo " -m only mail results"
echo " -s only send results to screen"
echo " (default is to do both)"
echo " wait-secs is seconds in between finger attempts (default 60)"
if [ $# = "0" ]
# Set default options, then check for command line switches
case "$1" in
case "$#" in
# Make sure we can finger that user
# If there's no such user, finger doesn't seem to exit with failure,
# but it does put the "no such user" message on stderr,
# so then the grep will fail and cause the if test to be false.
# (Search for "read" to match "Mail last read" AND "Unread since")
if finger -m "$UNAME" | grep 'read'
OLDTIME=`finger -m "$UNAME" | grep 'read' | sed -e 's/Mail last read//' -e
NEWTIME=`finger -m "$UNAME" | grep 'read' | sed -e 's/Mail last read//' -e
while [ "$NEWTIME" = "$OLDTIME" ]
test "$SCREEN" = "yes" && echo -n " " # To keep the window open
NEWTIME=`finger -m "$UNAME" | grep 'read' | sed -e 's/Mail last read//'
s/ *Unread since//'`
if [ "$SCREEN" = "yes" ]
echo "$UNAME is back."
finger -m "$UNAME" | grep 'read'
# Mail the notification
if [ "$MAIL" = "yes" ]
mail -s "$0" $USER <<EOF
$UNAME is back
-----------shell script ends
Express yourself instantly with MSN Messenger! Download today - it's FREE!