Building an "odometer" for time spent on a server Building an "odometer" for time spent on a server unix unix

Building an "odometer" for time spent on a server


Depending on your shell, you may be able to just spawn a process in the background when you log in, and then handle the kill signal when the parent process (the shell) exits. It wouldn't consume resources, you wouldn't need root privileges, and it should give a fairly accurate report of your logged in time.

You may need to use POSIX semaphores to handle the case of multiple shells logged in simultaneously.


Have you considered writing a script that can be run by cron every minute, running "who", looking at its output for lines with your uid in them, and bumping a counter if it finds any? (Use "crontab -e" to edit your crontab.)

Even just a line in crontab like this:

* * * * * (date; who | grep $LOGNAME)>>$HOME/.whodata

...would create a log you could process later at your leisure.