Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

solaris logindate script 2

Status
Not open for further replies.

sm42

Technical User
Dec 11, 2003
133
GB
hello

Scripting has never been my strength...

I would appreciate help to create a script that lists the last time if a user logged on or if they have ever logged on, the username, the GECOS and whether account is locked.

logindate username GECOS Lock Status

10 Nov 2007 10:18 smitht Ted Smith -
- paul Paul LK

I could take the login date from the finger command, some suggested to get this from the /etc/shadow file (field 3 i think)

Username can be taken from /etc/passwd as well as GECOS.
whether account is locked from filed 2 /etc/shadow

I'm struggling with capturing the last login date of a user.

I could get this from the wtmp file but this is a log file which is rotated, also truncated and is a data binary file, so I may need to cron a last and send the output to a file.

How would you capture the logindate of a user from the finger command ?
Since the finger command would tell you that a particular user has never logged on.

thanks in advance



 
All the information you require can be gained from the following commands:
cat /etc/passwd # usernames & gecos
finger <username> # gecos, current login time/last login/never logged in
logins -x -l <username> # gecos, password 'state' (password/no password/locked)

From the output you can 'collect' the data for the fields for display using the following:
grep and echo and awk and .....


I'm struggling with capturing the last login date of a user.
There are 3 cases:
1) a user is currently logged in.
2) a user was logged in previously
3) a user has never logged in

The output from the 'finger' command, line 3 looks like:
1) On since <Mmm dd hh:mm:ss> on <termi> from <host or IP-addr>
2) Last login <Day Mmm dd hh:mm> on <termi> from <host or IP-addr>
2) Last login <Day Mmm dd, yyyy> on <termi> from <host or IP-addr>
3> Never logged in.
(NB: there are 2 x 2)'s depending on how long ago the last login was - 'time' if in last 6 months or 'year' if longer than 6 months)

You will need to decide if your script displays the information for one username (supplied as a parameter) or all usernames on the system. Or, indeed, a combination of the two.

Please post further questions as you feel it necessary.

I hope that helps.

Mike
 
I like to use this command:

finger `sort /etc/passwd | cut -f1 -d":"` | grep -i log > outputfile.txt

- Stinney

Favorite all too common vendor responses: "We've never seen this issue before." AND "No one's ever wanted to use it like that before.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top