Operating System - HP-UX
1820146 Members
3155 Online
109620 Solutions
New Discussion юеВ

Re: easy way to tell idle time for interactive login

 
SOLVED
Go to solution
Scott Van Kalken
Esteemed Contributor

easy way to tell idle time for interactive login

I need an easy way to tell idle time for an interactive login.

if I do a w - I get:

ogriza01 pts/tYd 9:20am 30 11:13 11:13

this is all cool, but if the person isn't idle, the 30 is null.

I guess I need some way of splitting the line so that I can cater for the "is idle null" situation.

Any ideas?
8 REPLIES 8
Scott Van Kalken
Esteemed Contributor

Re: easy way to tell idle time for interactive login

I forgot to mention - this is from a script.
Michael Tully
Honored Contributor

Re: easy way to tell idle time for interactive login

Hi Scott,

The first thing you need to do is get the information into columns so that you can segregate the column that has a "null" value.

Here is a start:

w | awk '{print $1"|"$3"|"$4"|"$7"|"}'

Once you've done that you'll have to get the 'null' and remove them. I guess that's a challenge. I would reckon that perl will do this quite well. I'll have an experiment, and see what I can come up with. (time permitting...)

Cheers
Michael
Anyone for a Mutiny ?
Sridhar Bhaskarla
Honored Contributor
Solution

Re: easy way to tell idle time for interactive login

Hi,

You can do it with who.

Try who -uT and look for 7th column. It won't be null.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Scott Van Kalken
Esteemed Contributor

Re: easy way to tell idle time for interactive login

so far I've got a rather inelegant soloution of:

while read user tty login idle jcpu pcpu what
do
idlenull=$(echo $idle | grep -c ":")
if [ $idlenull -eq 0 ]
then
name=$(grep $user /etc/passwd | awk -F":" '{print $5}')
echo "$user - $name on $tty has been idle for $idle minutes and has a cumulative cpu of $jcpu"
fi
done

it's just grepping for the time component, which I know exists. If I get $idle (output from w) with what looks like a time component, it means that the idle is null.

Not very nice, just wondering if there's a better way.

Scott.
Sridhar Bhaskarla
Honored Contributor

Re: easy way to tell idle time for interactive login

Hi Scott,

Check this script


#!/usr/bin/ksh
HOST=$(hostname)
EVERY=1

MESSAGE="please consider logging out"
SUBJECT="You are IDLE on $HOST"

get_user()
{
USER=$(echo $LINE|awk '{print $1}')
IDLE=$(echo $LINE|awk '{print $6}')
if [ "$IDLE" = "old" ]
then
echo $MESSAGE |mailx -s $ SUBJECT $USER
else
IDLE_HOURS=$(echo $IDLE|awk '{FS=":";print $1}')
if [ "$IDLE_HOURS" -ge 1 ]
then
echo $MESSAGE |mailx -s $ SUBJECT $USER
fi
fi
}
who -u|while read LINE
do
get_user $LINE
done

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Scott Van Kalken
Esteemed Contributor

Re: easy way to tell idle time for interactive login

amazing...
as soon as I started to use the who -T stuff, I came up with something very similar.

Sort of.

I'm also looking for high cumulative CPU time. This in combination with idle time lets me know those people who are running large jobs online during the day.

When I find them, they'll get a call from their friend unix admin with a suggestion that they can run whatever they're running overnight.

Thanks for all the help guys.

Scott.
James R. Ferguson
Acclaimed Contributor

Re: easy way to tell idle time for interactive login

Hi Scott:

If the goal is to divest yourself of sessions without activity for n-seconds, consider setting the TMOUT variable. If set to a value greater than zero (seconds), the shell will terminate TMOUT seconds after a PS1 prompt is issued and no input is received.

You could set the TMOUT value in the user's profile. Setting the TMOUT 'readonly' will prevent the user from overriding it:

# TMOUT=10;readonly TMOUT

Regards!

...JRF...

Scott Van Kalken
Esteemed Contributor

Re: easy way to tell idle time for interactive login

unfortunately TMOUT isn't an option. I don't want to look for just idle sessions.

I'm trying to find out people who log in three times and run huge reports or whatever during the day.

I guess I'm trying to identify those people, find out what they're doing, then try to get them to run this stuff overnight.