I'm in search for a light-weight shell script that will capture user logon and logoff and send the results to .csv file on a windows network share. Any helpful direction would be most appreciated.
Thank you
-Paul
The unix command, 'last' tells you who logged in and when. You could easily grab the login details from there and use crontab for delivery or collection.
If you wanted to do it once a day at 1am and have it emailed out, for example, you could write the following crontab entry:
01 01 * * * rm /tmp/last.*.log ; last > /tmp/last.`date +%F`.log; cat /tmp/last.*.log | mail -s "logins for today"
[email protected]
If the location is locally writeable, ie, you can see it in /Volumes, change the last argument to 'mv' the file instead of email it.
If you're looking to format the file, when you do the 'last > /tmp/log' bit, you can do some scripting using perhaps 'awk' or 'sed' to change the text to how you want it.
For example, to grab the 1st and 3rd columns of the last command, separated by a comma, you'd do the following:
last | awk '{print $1","$3}' > /tmp/last.log
Hope I've made sense and haven't gone too deep!
G