Script to identify logged users & commands executed

Hi All,
I am trying to write a script to get the user information & the command executed.

I tried something like this :

w | sort | awk '{print$5$6$7}'

My requirement is to identify the users who execute the same command at same time.

I need the user name & the command in a separate file.

For ex :

User a executing rm command at 12 hrs
User b executing rm command at 12 hrs

then i need the o/p file as

User A rm 12hrs
User B rm 12 hrs

Can some one give any idea on this.

Thanks,
Vijay

w tell what is happening just now. Are you interesting about ex. rm using or which command they use long period or which command need lot of cpu or only current situation and how much they have used something or if user A are using sh and sh and sh, total of user A using sh or ...

Just now:
w | sort -k 7,7 -k 1,1 | awk '{print $1,$6,$7}'

ps -ef | sort -k 8,8 -k 1,1 -k 7,7 | awk '{print $1,$8,$7}'

Hi,
Thanks... The commands you gave lists the data but then i am looking to identify the users who run a same command at the same time.

Example is User A & User B running the command cp at same time
then i need to take the o/p like

User A cp 12 hrs
User B cp 12 hrs

something like this.

If you get some idea plz let me know.

Thanks,
Vijay