Script: users

I need to make a script which does the following:

  • Display users logged on
  • Which sessions open
  • What they are doing atm.
  • To which group they belong
  • How long they are active or not

This is what I got now:

 
  echo " " 
  echo Number of sessions:
  ps v | grep "pts" | awk '{ print $2 }' | wc -l   <------------ this is not ok yet
   
  echo " "
   
  echo "Most Frequent Process:  "
  ps -ef | awk '{ print $1 $8 }' | uniq -c | sort -r | nl | awk '{ print $1 " "  $3 }' | grep "^1 " | awk '{ print $2}'
  

This works if there is one user online. But it will probably not work for more than one user... Guess I need a loop to do that... Would be nice if you could give me a hand :rolleyes:. I'm not really good at this, and I'm sure that I can do most things a bit more simple :/. I'm a newbie too :stuck_out_tongue:

  1. Instead of

use

 echo 'and is doing the following:' ` w -h | awk '{print $NF}'` 
  1. use sort before using uniq...

should be $USER

  1. After this show me your output and desired output...will try to help.

This is my output :slight_smile:

I would like to check if this would work for more than one user... I really don't know how. I also don't know how to display all the user's "sessions".

btw. edited my code with yours :slight_smile:

  1. I do not see any output.
  2. Its working for more than 1 user but first all the user-ids come then count and then their tasks etc...
    do yoou want all the details of first user then second user...and so on so forth...

I don't know what you mean with output btw :(. This is what I got when I ran the script...

Actually I want this for the users thing:

  • The user his accountname + sessions open + what he is doing atm. + to which group he belongs + how long active...
    So for example:

USER 1
Sessions open:
What he is doing
Groups
Active

USER2
...
...
...
...

USER3

put this piece of code in loop

  echo $USERS belongs to group `groups $USERS`
 echo 'and is doing the following:' ` w -h | awk '{ print $NF }'`
  echo The user is online since `who | awk '{ print $4}'`
  echo " "

for _user in `who | cut -f"1"
do
echo user = $_user
echo group = `groups $_user`
echo doing=`w -h $_user | awk '{ print $NF }'`
echo online since =`w $_user | tail -1 | awk '{ print $3 }'`
done

this should work.

Yeah it works!

I need to add one more thing: "sessions". These are not processes and I really have no idea where to find them :/. I also need to add how many sessions there are.
The user sessions should be added in the loop.

As you can see in the "Summary"
There are 3 things there:

  • total users
  • total sessions [not correct atm]. Do I need to use who -a ?
  • most frequent process

Could you check these too please? Thanks a lot though!

Not sure. who -a may not work, I think.
try manipulating ps. grep for ksh, sh, csh etc.

You make it look so simple lol. I'll try :o

-----Post Update-----

Ehhhmm... I really don't know where to look :P. I googled it and found something about utmp... Can that be useful?

-----Post Update-----

Sorry for this double post but I still haven't found the sessions thing. I don't even know where to look for :confused:

-----Post Update-----

You can close this. I got all the answers I need!