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 
- Instead of
use
echo 'and is doing the following:' ` w -h | awk '{print $NF}'`
- use sort before using uniq...
should be $USER
- After this show me your output and desired output...will try to help.
This is my output 
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 
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 
-----Post Update-----
You can close this. I got all the answers I need!