Hi all,
First time post, so please be gentle.
I'm writing a Solaris 10 ksh script to retrieve details of logins and logouts using specific user names. The details I want are quite basic - the username, the computer logged in from, and the date and time the user logged in and logged off.
I initially thought that the 'last' command would be perfect, however its output doesn't include a year in its date information, which I need.
After further searching on this site and others I came across the fwtmp command, which I can use as follows to read the information I need:
/usr/lib/acct/fwtmp < /var/adm/wtmpx > temp_ascii_login_file.txt
This works fine and returns a plain text file that includes full year information in the date, but the problem is that I don't understand all of the fields contained in the output.
As far as I can tell, if field 5 contains a 7, the entry shows a login, and if field 5 contains an 8, the entry shows a logout. Assuming this is correct, I've written the following nawk commands to extract the information I need:
nawk '$1 == "username" && $5 == "8" {print $1, $3, $4, $5, $12, $13, $14, $15, $16}' temp_ascii_login_file.txt > myoutput.txt
nawk '$1 == "username" && $5 == "7" {print $1, $3, $4, $5, $13, $14, $15, $16, $17, $12}' temp_ascii_login_file.txt >> myoutput.txt
I appear to need different commands for the logins and logouts, as the record structure seems to be a bit different for each.
I'm then sorting the file using the following command:
sort -k 3,3 -k 9,9 -k6M myoutput.txt
This seems to sort each login record chronologically, with its corresponding logout on the following line.
What I want to know is, are my assumptions about the output format of fwtmp correct? Also, will my sort command group all the results as I've outlined?
I've tried to find a reference that explains in plain english what the format of the fwtmp output is, but have not been successful. The best I've found is someone advising to run the command 'man 4 utmpx', which does seem related, but this refers to a c header file (utmpx.h), and my c is a bit rusty at this stage. :o
If someone could respond to my concerns, and point me in the direction of an explanation of the ascii output of the fwtmp command I'd be grateful.
Apologies if this has been answered before, but I don't think it has. Thanks in advance for any assistance anyone can provide.
Regards,
cA.