Number of times a user is "connected"?

hi i wish make a shell to look for the number of times a user is connected then makes a "whatch dog" by crontab to handle this
i could do it through ps-fedal| grep user_name | wc-l ... etc.

but others suggested me another algorithm :mad:
and thought to use w, or finger, or who
but it have a problem
if I try (as root) open a command interpreter and use
su username
none of the above commands recognize me as the new user where I am, It still recognize as root :frowning:

how could I fix this? or which other command allows me to see what actions or process a user doing on the machine? :confused:.

by the way im from colombia and im an Unix's (CentOS 5) novice user :stuck_out_tongue:
thank you very much for your comprention and attention

Are you worried that other users are doing bad things on your computer? Trying to monitor interactively (what you are asking) means you have to sit 24 hours a day and look at other processes.

This will give you what you just asked for, if I understood:

who | awk 'arr[$1]++;  END{for(i in arr){print i, arr }}'

I don't think that is what you want to do. There are other solutions. What kinds of processes are you worried about? By that I mean are they internet connections, telnet connections, ssh connections, ftp connections....?

As a very general apporach I would learn about and install snort, and learn how to set up accounts for other users so they are restricted - like a restricted shell, or a chroot jail.
You have a lot of reading.....

Snort :: Home Page

Restricted shells
Restricted Shells

chroot jail for sftp and ftp howto:
https://help.ubuntu.com/community/BasicChroot