RE: notification of user login
Caveman wrote
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
localhost.)
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)
#!/bin/sh
syntax(){
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)"
exit 1
}
if [ $# = "0" ]
then
syntax
fi
# Set default options, then check for command line switches
MAIL=yes
SCREEN=yes
case "$1" in
-m) SCREEN=no
shift
;;
-s) MAIL=no
shift
;;
esac
case "$#" in
1) UNAME=$1
WAITTIME=60
;;
2) UNAME=$1
WAITTIME=$2
;;
*) syntax
;;
esac
# 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'
then :
else
exit 1
fi
OLDTIME=`finger -m "$UNAME" | grep 'read' | sed -e 's/Mail last read//' -e
's/ *
Unread since//'`
NEWTIME=`finger -m "$UNAME" | grep 'read' | sed -e 's/Mail last read//' -e
's/ *
Unread since//'`
while [ "$NEWTIME" = "$OLDTIME" ]
do
sleep $WAITTIME
test "$SCREEN" = "yes" && echo -n " " # To keep the window open
NEWTIME=`finger -m "$UNAME" | grep 'read' | sed -e 's/Mail last read//'
-e '
s/ *Unread since//'`
done
if [ "$SCREEN" = "yes" ]
then
echo "$UNAME is back."
finger -m "$UNAME" | grep 'read'
fi
# Mail the notification
if [ "$MAIL" = "yes" ]
then
mail -s "$0" $USER <<EOF
$UNAME is back
EOF
fi
-----------shell script ends
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
Reply to: