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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with C-shell script

Status
Not open for further replies.

Ciralia

Programmer
Oct 22, 2002
51
US
I need to write a script to print out all user login activity. I know that the "last" command shows that information, however, I would like the output to look something like this:

Lets say user joe logged in 10 times and user sam logged in 25 times. I want output to be like this:

joe 10
sam 25

And nothing else. I could not find any flags for the last command at all.

Any help is appreciated =)
 
Well to get the numbers of times the user has logged in you can run the following command..

last | grep <username> | wc -l

You will still have run some kind of awk command to parse the last output to get each users name.
 
penelope# foreach USER (`last | grep -v reboot | cut -f1 -d' ' | sort -u`)
? setenv COUNTER `last|grep $USER | wc -l`
? echo $USER logged in $COUNTER times
? end
ftp08 logged in 17 times
root logged in 240 times
wtmp logged in 1 times
penelope#


Best Regards, Franz
--
Solaris System Manager from Munich, Germany
I used to work for Sun Microsystems Support (EMEA) for 5 years
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top