Are you just trying to log logins and logouts for a single server? I'm confused about where the client machines come in... Unless you want to log logins on each client machine as well...
Depending on your distribution, logins and logouts are typically logged in /var/log/messages, or /var/log/auth.log.
If you are tracking logins on several machines and want to keep a central log, you may want to look into remote syslog. That way you could have syslog do all the work, and there would be no need for a script at all.
Let us know if you still need help! I'm probably completely missing the point!