Discussion:
Auto update
(too old to reply)
Jos Chrispijn
2010-04-11 06:14:48 UTC
Permalink
Can someone tell me if there is a way of generating an email on the
moment that someone logs in to my FreeBSD server? The mail part
(phpmail) will be easy; I don't know yet how to trigger and pass
parameter to this script or redirect info to a file (that I then send by
email). Thanks.

Jos Chrispijn
andrew clarke
2010-04-11 06:27:34 UTC
Permalink
Post by Jos Chrispijn
Can someone tell me if there is a way of generating an email on the
moment that someone logs in to my FreeBSD server?
By which method? SSH?
Jos Chrispijn
2010-04-11 09:27:43 UTC
Permalink
Post by andrew clarke
By which method? SSH?
Yes, sorry I didn't mention that. If possible on both SSH and otherwise.

Thanks,
Jos
Doug Hardie
2010-04-11 07:41:01 UTC
Permalink
Can someone tell me if there is a way of generating an email on the moment that someone logs in to my FreeBSD server? The mail part (phpmail) will be easy; I don't know yet how to trigger and pass parameter to this script or redirect info to a file (that I then send by email). Thanks.
A cheesy way to do that is to use a popen ("tail -f /var/log/auth.log", "r") and then read that. It will give you every login regardless of ssh, telnet etc. You could then generate the emails from that. I have no idea just how resource intensive this might be. You would also have to ensure it got started by rc during boot._______________________________________________
freebsd-***@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-***@freebsd.org"
Jos Chrispijn
2010-04-11 09:32:27 UTC
Permalink
Post by Doug Hardie
A cheesy way to do that is to use a popen ("tail -f
/var/log/auth.log", "r") and then read that. It will give you every
login regardless of ssh, telnet etc. You could then generate the
emails from that. I have no idea just how resource intensive this
might be. You would also have to ensure it got started by rc during
boot._______________________________________________
In order to find out if someone logged in, I should then first copy
auth.log to auth2.log, and do a compare and then do the tail trick. Have
to cron that every half a minute.
I would like to know if there is something that is alterted on the
moment that someone logs on thus forcing evt. your tail suggestion

thanks,
Jos Chrispijnj
Ed Jobs
2010-04-11 10:17:36 UTC
Permalink
Post by Jos Chrispijn
In order to find out if someone logged in, I should then first copy
auth.log to auth2.log, and do a compare and then do the tail trick. Have
to cron that every half a minute.
I would like to know if there is something that is alterted on the
moment that someone logs on thus forcing evt. your tail suggestion
thanks,
Jos Chrispijnj
you could try using syslog to do that. check the man page of syslog.conf, and
search for "auth." you could then populate a file with the successful logins
as they happen
--
Real programmers don't document. If it was hard to write, it should be hard to
understand.
RW
2010-04-11 12:11:57 UTC
Permalink
On Sun, 11 Apr 2010 11:32:27 +0200
Post by Jos Chrispijn
Post by Doug Hardie
A cheesy way to do that is to use a popen ("tail -f
/var/log/auth.log", "r") and then read that. It will give you every
login regardless of ssh, telnet etc. You could then generate the
emails from that. I have no idea just how resource intensive this
might be. You would also have to ensure it got started by rc during
boot._______________________________________________
In order to find out if someone logged in, I should then first copy
auth.log to auth2.log, and do a compare and then do the tail trick.
Have to cron that every half a minute.
I would like to know if there is something that is alterted on the
moment that someone logs on thus forcing evt. your tail suggestion
tail -f *is* event driven. When a new line is appended to auth.log,
tail will output it.

You should probably use

$ tail -F -n 0 /var/log/auth.log
krad
2010-04-11 17:16:01 UTC
Permalink
Post by RW
$ tail -F -n 0 /var/log/auth.log
Definitely use the -F rather than -f option as it will handle log rotation
Randal L. Schwartz
2010-04-11 17:32:06 UTC
Permalink
Jos> In order to find out if someone logged in, I should then first copy auth.log
Jos> to auth2.log, and do a compare and then do the tail trick. Have to cron that
Jos> every half a minute.

No, just track it with tail -f as was already suggested.

tail -f /var/log/authlog | while read aline; do; ... ; done

The code in the middle will get executed as each line appears in the
file. This even survives authlog renaming when you logroll.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<***@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
krad
2010-04-12 08:44:57 UTC
Permalink
Post by Randal L. Schwartz
Jos> In order to find out if someone logged in, I should then first copy auth.log
Jos> to auth2.log, and do a compare and then do the tail trick. Have to cron that
Jos> every half a minute.
No, just track it with tail -f as was already suggested.
tail -f /var/log/authlog | while read aline; do; ... ; done
The code in the middle will get executed as each line appears in the
file. This even survives authlog renaming when you logroll.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "
no use -F not -f as log rotation will break it otherwise

krad
2010-04-11 17:13:29 UTC
Permalink
Post by Jos Chrispijn
Can someone tell me if there is a way of generating an email on the
moment that someone logs in to my FreeBSD server? The mail part (phpmail)
will be easy; I don't know yet how to trigger and pass parameter to this
script or redirect info to a file (that I then send by email). Thanks.
A cheesy way to do that is to use a popen ("tail -f /var/log/auth.log",
"r") and then read that. It will give you every login regardless of ssh,
telnet etc. You could then generate the emails from that. I have no idea
just how resource intensive this might be. You would also have to ensure it
got started by rc during boot._________________________
It shouldn't be to bad as I use that method to generate stats from log files
for snmp. The log files I tail have about 200 odd lines per second and the
boxes handle it fine. But they are decentish spec but not extravagant (dell
2850 with 4gig ram)
Loading...