Script to find systems logged in with a particular userid

Hello All,

I need to design a script to get all the systems names(IP Addresses) logged in with a particular userid say 'xyz' from different terminals. This is to track the use of the particular userid and take action if it is being misused.
The script would accomplish the following steps:

  1. the script should run at all times
  2. it should find out who all are logged in with username say 'xyz' with the system names(IP Addresses)
  3. it should constantly write that with timestamp to a file
  4. after each 24 hours it should send a mail to a email address, say : admin@abc.com with the file as attachment.

Any help will be much appreciated.

Thanks in Advance!!

with warm regards,
Himadri S Mazumder

That's already logged by the system. Take a look at the man pages for who and last. For example, in Linux you can get all the logins/logouts for the current day using

last -Fai | grep -E "$(LANG=C date '+%b %e').+$(date '+%Y')"