Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Jul 2002 21:02:16 -0600 (CST)
From:      Ryan Thompson <>
To:        sagacious <>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Watching users
Message-ID:  <>
In-Reply-To: <000001c2337c$5db576d0$0a01a8c0@MIKESBOX>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
sagacious wrote to freebsd-questions@FreeBSD.ORG:

> Hello list,
>  I need to watch either via an open terminal, using "Watch" or some
> other method. I remember seeing fortune freebsd-tips saying how if I
> used tcsh I could type a command that would tell me everyone who
> logs in and out of my system. Can you please tell me how I can have
> a daemon or prog running that will do nothing except log logins via
> sshd and ftp to a file, or better yet, email me when someone logs
> in? I have watch installed and I am about to hit the manpage but I
> posted here first because I don't think watch will do what I want it
> to. The ideal thing would be for "it" to email me whenever someone
> logs in or out. Thanks.

Hmm... So you want something that will simply just flip a switch and
let you know if/when someone logs in or out. I won't ask why. :-)

The shell script solution (run this as yourself from cron once per
minute). This is untested, by the way. :-)

[ ! -e /tmp/who.last ] && /usr/bin/touch /tmp/who.last
if [ ! -f /tmp/who.last ]; then
  echo /tmp/who.last is not a regular file!
  exit 1
/usr/bin/who | /usr/bin/diff /tmp/who.last -
/usr/bin/who > /tmp/who.last

You'll get a diff output mailed to the owner of the cron task, or no
output (and no email) if nobody logged in our out in the last minute.
Test it, though, before you turn it on and leave for a week.

Better yet, run as nobody and send the output to mail yourself. Or
mail it to your cell phone if you want audio feedback. :-)

The script should be reasonably secure, but I haven't even verified
that it works, so I make no guarantees whatsoever. :-)

- Ryan

  Ryan Thompson <>

  SaskNow Technologies -
  901 1st Avenue North - Saskatoon, SK - S7K 1Y4

        Tel: 306-664-3600   Fax: 306-244-7037   Saskatoon
  Toll-Free: 877-727-5669     (877-SASKNOW)     North America

To Unsubscribe: send mail to
with "unsubscribe freebsd-questions" in the body of the message

Want to link to this message? Use this URL: <>