Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to detect when someone logs in?

0 views
Skip to first unread message

Tony Christian Söderudd

unread,
Feb 2, 1998, 3:00:00 AM2/2/98
to

Suppose I want to be notified when my friend logs on to a computer.
How is it done? In irc I can use the notify command but how about
in plain unix shell? Is it possible to do a script that 'watches'
when user e75239 logs in and notifies me?
Please help!

Thanx

Tony Söderudd -- e75...@uwasa.fi

--


Pete Houston

unread,
Feb 2, 1998, 3:00:00 AM2/2/98
to

This is a feature of some of the more fancy shells: tcsh has it, zsh has
it (AFAIK), and probably rc. However, by far the nicest way to do this
is with znol which comes with the zephyr package under athena. I would
go this way first, if it were an option.

Tony Christian Söderudd <e75...@vilkku.uwasa.fi> wrote in comp.unix.shell:


|Suppose I want to be notified when my friend logs on to a computer.
|How is it done? In irc I can use the notify command but how about
|in plain unix shell? Is it possible to do a script that 'watches'
|when user e75239 logs in and notifies me?

Pete
--
J.J. Thomson Physical Laboratory | Email: p.h.r....@reading.ac.uk
PO Box 220, Whiteknights, Reading, | Phone: +44-118-9875123 ext 7594
Berkshire, RG6 6AF, United Kingdom | Fax: +44-118-9750203
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WWW: http://www.rdg.ac.uk/~spr96phh/pete.html Use lynx - you know you want to!


Fritz

unread,
Feb 2, 1998, 3:00:00 AM2/2/98
to

I suppose it would depend on how "fancy" you wanted to get. You could
write a very simple shell script to do "who | grep e75239" every minute
(using "sleep") and mail/write you a message when it is successful.

Tony Christian Söderudd wrote:

> Suppose I want to be notified when my friend logs on to a computer.
> How is it done? In irc I can use the notify command but how about
> in plain unix shell? Is it possible to do a script that 'watches'
> when user e75239 logs in and notifies me?

James R. Martin

unread,
Feb 4, 1998, 3:00:00 AM2/4/98
to

Pete Houston (pe...@sppc75.reading.ac.uk) wrote:
: This is a feature of some of the more fancy shells: tcsh has it, zsh has

: it (AFAIK), and probably rc. However, by far the nicest way to do this
: is with znol which comes with the zephyr package under athena. I would
: go this way first, if it were an option.

Why go through all the trouble when all one has to do is write a script:

script waituser:

until who | grep -s ${1:?'usage: waituser login-name'} >/dev/null
do sleep 30
done
echo $1 logged on >/dev/tty

$ waituser friend_login &

-James

Kurt Schwind

unread,
Feb 4, 1998, 3:00:00 AM2/4/98
to

Tony Christian Söderudd wrote:
>
> Suppose I want to be notified when my friend logs on to a computer.
> How is it done? In irc I can use the notify command but how about
> in plain unix shell? Is it possible to do a script that 'watches'
> when user e75239 logs in and notifies me?
> Please help!

If you have access to cron, you can periodically run a script that
checks to see if a certain user has logged on and notifies you when they
do. All you have to do is have a script that runs a who and greps for
your friends loginid. If greps returns a success, email yourself from
the script. Now this script wouldnt' tell you 'right' when an ID logs
in. It would tell you if that person was logged in when the script
ran. Depending on how often you run your script (every 5 mins?) you may
actually miss someone.

--
Kurt Schwind | Delta State University
DataBase Analyst/Systems Manager | http://www.deltast.edu
Kethley 126 | Vox Phone:601.846.4030
ksch...@dsu.deltast.edu | I C Q Number: 3624215

a...@sasi.com

unread,
Feb 5, 1998, 3:00:00 AM2/5/98
to

In article <6b8les$5bo$6...@sjs-news-01.blueneptune.com>,

I think who allows u to check for the logging in of the user on
the machine from which u r running the script. How about using
finger instead?

#!/bin/csh

set logged=0
while ( $logged < 1 )
set logged=`finger '@'$2 | grep -i $1 | wc -l`
if ( $logged > 0 ) then
echo "user $1 logged in"
endif
end

With warm regards
Arijit.

-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet

Mike Kleiman

unread,
Feb 5, 1998, 3:00:00 AM2/5/98
to

Here's a very simple script that will look every 60 seconds to see if some
user has logged in. It will ring the bell and print a message when they
arrive.

You'll probably want to run this in the back ground - just a thought....

-------------------------------------------------------------
until who | grep $1 > /dev/null
do
sleep 60
done

print "\007 $1 has logged on"
-------------------------------------------------------------

Mike Kleiman


Kurt Schwind <ksch...@dsu.deltast.edu> wrote in article
<34D8EF9C...@dsu.deltast.edu>...

Pete Houston

unread,
Feb 5, 1998, 3:00:00 AM2/5/98
to

I (pe...@sppc75.reading.ac.uk) wrote:
|: This is a feature of some of the more fancy shells: tcsh has it, zsh has
|: it (AFAIK), and probably rc. However, by far the nicest way to do this
|: is with znol which comes with the zephyr package under athena. I would
|: go this way first, if it were an option.

James R. Martin <jrma...@rainey.blueneptune.com> wrote in comp.unix.shell:


|Why go through all the trouble when all one has to do is write a script:

Because I think it's easier to type

znol on

than to write the script. No trouble there.

Sitaram Chamarty

unread,
Feb 6, 1998, 3:00:00 AM2/6/98
to

On Mon, 02 Feb 1998 22:48:13 -0500, Fritz <fr...@fuse.net> wrote:
>I suppose it would depend on how "fancy" you wanted to get. You could
>write a very simple shell script to do "who | grep e75239" every minute
>(using "sleep") and mail/write you a message when it is successful.

Or, if you have your friend's co-operation, you could have him put a line into
his .profile that would (1) check if you were logged on, and then (2) would
send you a "write" message or something. No polling every 60 seconds!

(You did say "friend", not "boss", right :-)

>
>Tony Christian Söderudd wrote:
>
>> Suppose I want to be notified when my friend logs on to a computer.
>> How is it done? In irc I can use the notify command but how about
>> in plain unix shell? Is it possible to do a script that 'watches'
>> when user e75239 logs in and notifies me?
>> Please help!
>>

Seth

unread,
Feb 12, 1998, 3:00:00 AM2/12/98
to

-----BEGIN PGP SIGNED MESSAGE-----


Then again, if one has tcsh, you could use the watch statement:

set watch = (user term)

For example, if you wanted to see if bill, bob, and harry were logged in,
you could put this in your .cshrc:

set watch = (bill any bob any harry any)


On Thu, 5 Feb 1998 a...@sasi.com wrote:

- --->In article <6b8les$5bo$6...@sjs-news-01.blueneptune.com>,
- ---> jrma...@rainey.blueneptune.com (James R. Martin) wrote:
- --->>
- --->> Pete Houston (pe...@sppc75.reading.ac.uk) wrote:
- --->> : This is a feature of some of the more fancy shells: tcsh has it, zsh has
- --->> : it (AFAIK), and probably rc. However, by far the nicest way to do this
- --->> : is with znol which comes with the zephyr package under athena. I would
- --->> : go this way first, if it were an option.
- --->>
- --->> Why go through all the trouble when all one has to do is write a script:
- --->>
- --->> script waituser:
- --->>
- --->> until who | grep -s ${1:?'usage: waituser login-name'} >/dev/null
- --->> do sleep 30
- --->> done
- --->> echo $1 logged on >/dev/tty
- --->>
- --->> $ waituser friend_login &
- --->>
- --->> -James
- --->
- --->I think who allows u to check for the logging in of the user on
- --->the machine from which u r running the script. How about using
- --->finger instead?
- --->
- --->#!/bin/csh
- --->
- --->set logged=0
- --->while ( $logged < 1 )
- ---> set logged=`finger '@'$2 | grep -i $1 | wc -l`
- ---> if ( $logged > 0 ) then
- ---> echo "user $1 logged in"
- ---> endif
- --->end
- --->
- --->With warm regards
- --->Arijit.
- --->
- --->-------------------==== Posted via Deja News ====-----------------------
- ---> http://www.dejanews.com/ Search, Read, Post to Usenet
- --->
- --->

- ------------------------Seth Weith-Glushko------------------------
- --------------...@mail.bergen.org----------------------
- ---------------------users.bergen.org/~setwei---------------------
- ---------Life is what happens when you are making plans.----------

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBNONGmb9rZlyICbSNAQH1KAP6A7PIISAPioPukncz4CpxyZtvKdoYY8po
b81Pg+bK47deim+92cINB+/x7GHY//FUoyYaQvgpfLOIwsfq+orZ7CUBlLIVmHcA
0ooLS4yPl4xEmhbF5UTHJqlwZUQGXk8qShIkJvYGnissreIubMLhj9iRztVK/x1i
nXvi9QIFec0=
=PEdX
-----END PGP SIGNATURE-----


era eriksson

unread,
Feb 15, 1998, 3:00:00 AM2/15/98
to

On 2 Feb 1998 12:51:46 GMT, e75...@vilkku.uwasa.fi (Tony Christian
Söderudd) posted to comp.unix.shell:

> Suppose I want to be notified when my friend logs on to a computer.
> How is it done? In irc I can use the notify command but how about
> in plain unix shell? Is it possible to do a script that 'watches'
> when user e75239 logs in and notifies me?

Here's what I'm using for watching folks on a host I'm logged into
myself. This is a bit nicer than running who(1) once a second or
whatever (but do note that some types of logins are not visible in
wtmp on some systems).
This is not really portable, but I've managed to run it on Linux and
OSF/1 (with a couple of minor modifications). Some OSes don't seem to
have all the fields I would like to watch in wtmp.

Check the location of wtmp (Linux nicely defines _PATH_WTMP for you
but this is my OSF/1 copy).

Comments and improvements welcome.

/* era */


/* view wtmp
era Wed Oct 15 15:21:41 1997
*/

#include <utmp.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <paths.h>

int main (int argc, char **argv)
{
struct utmp wtmp;
int fd;

if ((fd = open ("/var/adm/wtmp", O_RDONLY)) == -1)
exit (1); /* An error message would be nice ... */
if (! lseek (fd, 0L, SEEK_END))
exit (2); /* Ditto */

while (1)
if (read (fd, &wtmp, sizeof(wtmp)) == sizeof (wtmp))
if (*wtmp.ut_user != '\0')
printf ("%0.8s@%0.16s: %0.12s\n", wtmp.ut_user,
wtmp.ut_host, wtmp.ut_line);
else
printf ("%s logged out\n", wtmp.ut_line);
else
sleep (1);

/* Never actually falls through to here anymore ... */

close (fd);

return (0);
}

Bobby Higgins

unread,
Feb 15, 1998, 3:00:00 AM2/15/98
to

era eriksson wrote:
>
> On 2 Feb 1998 12:51:46 GMT, e75...@vilkku.uwasa.fi (Tony Christian
> Söderudd) posted to comp.unix.shell:
> > Suppose I want to be notified when my friend logs on to a computer.
> > How is it done? In irc I can use the notify command but how about
> > in plain unix shell? Is it possible to do a script that 'watches'
> > when user e75239 logs in and notifies me?
>
> Here's what I'm using for watching folks on a host I'm logged into
> myself. This is a bit nicer than running who(1) once a second or
> whatever (but do note that some types of logins are not visible in
> wtmp on some systems).
> This is not really portable, but I've managed to run it on Linux and
> OSF/1 (with a couple of minor modifications). Some OSes don't seem to
> have all the fields I would like to watch in wtmp.
>
> Check the location of wtmp (Linux nicely defines _PATH_WTMP for you
> but this is my OSF/1 copy).
>

Looks good works great. One little side note, most Unixes that I have
worked with the utmp/wtmp files have a definition for
#define WTMP_FILE /var/adm/wtmp
in their /usr/include/utmp.h.
The path may differ on some systems.

--
__o NO FEAR 'rm: text file busy'
_`\<,_ Bobby Higgins email: bobby....@ps.net
(_)/ (_) Home email: bhig...@swbell.net
************ peddlin' as fast as I can

0 new messages