From owner-freebsd-questions Wed Jul 24 20: 2:37 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4733D37B400 for ; Wed, 24 Jul 2002 20:02:34 -0700 (PDT) Received: from ren.sasknow.com (ren.sasknow.com [207.195.92.131]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7E39443E70 for ; Wed, 24 Jul 2002 20:02:33 -0700 (PDT) (envelope-from ryan@sasknow.com) Received: from localhost (ryan@localhost) by ren.sasknow.com (8.11.6/8.11.6) with ESMTP id g6P32Gc95253; Wed, 24 Jul 2002 21:02:16 -0600 (CST) (envelope-from ryan@sasknow.com) Date: Wed, 24 Jul 2002 21:02:16 -0600 (CST) From: Ryan Thompson To: sagacious Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Watching users In-Reply-To: <000001c2337c$5db576d0$0a01a8c0@MIKESBOX> Message-ID: <20020724204502.E92334-100000@ren.sasknow.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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. :-) #!/bin/sh [ ! -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 fi /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 - http://www.sasknow.com 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 majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message