1825748 Members
2442 Online
109687 Solutions
New Discussion

kill idle user

 
SOLVED
Go to solution
Sridhar Bhaskarla
Honored Contributor

Re: kill idle user

Attach 'who -u' output file rather than copy-paste.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
peterchu
Super Advisor

Re: kill idle user

thx reply , please find the attach file
Sridhar Bhaskarla
Honored Contributor

Re: kill idle user

Hi Peter,

who -u output looks the same as on HP-UX system. So the script should work.

Copy and paste the script exactly like it is. Add a 'done' at the end as i missed it.. It should work.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor

Re: kill idle user

Peter - If it still doesn't work, then add 'set -x ' at the beginning of the script and post the output. I don't have a linux system to test it...

-Sri
PS: Give me 0 points for all the posts in this thread.
You may be disappointed if you fail, but you are doomed if you don't try
peterchu
Super Advisor

Re: kill idle user

thx reply ,

I run it , the error output like this, could suggest what should I make so that I can use it at Linux ? thx

kill_user: line 38: [: 175:: integer expression expected
edp_usr:175::12650:Untouched

Robert Salter
Respected Contributor

Re: kill idle user

peter,

I've used this script for years and had no problems. It should work on Linux as well, albeit I don't have a Linux box to test on.

Later,

Bob
Time to smoke and joke
peterchu
Super Advisor

Re: kill idle user

thx robert's script , but the script that Muthukumar provide is easy to understand and suit for me and only have a little problem , thx your afford and sorry to my ignorance .

when I run Muth's script , i got the below error
./killuser: line 47: [: 00:09: integer expression expected ,

the line 47 is this line, i can run it smoothly at unix , could suggest how should I change it ? thx
if [ $time -gt $TIMEOUTT ]

Bharat Katkar
Honored Contributor

Re: kill idle user

hi,
try using
while (($time > $TIMEOUTT))
do
.
.
.
.
done

instead of
if [ $time -gt $TIMEOUTT ]

Regards,
You need to know a lot to actually know how little you know
hpuxrox
Respected Contributor

Re: kill idle user

Nice scripts, but it all sounds like overkill

If you want to kill an idle user, why not just set the value of TMOUT=360 in the users shell.
peterchu
Super Advisor

Re: kill idle user

thank again all replies,

I still can't find the reason why my script can only run at unix but can't at linux box.

the error is
./kill_idle: line 38: [: 00:03: integer expression expected , where line 38 is "if [ $time -gt $TIMEOUT ]" , I tried the below but still can't run .
(1)
while (($time > $TIMEOUTT))
do
.
.
.
.
done
(2)
if [[ $time -gt $TIMEOUTT ]]

my script is as below , could suggest how can I modify it to make it work ? thx


#!/bin/sh

PATH=$PATH:/usr/bin:/usr/sbin:/usr/contrib/bin
TIMEOUT=40
EXCEPTIONLIST=~ckyoung/exception.lst
touch $EXCEPTIONLIST

kill_pid()
{
PID=$1
kill -9 $PID
}

echo "User:Activity:PID:Status"
who -u | while read line
do
time=$(echo $line | awk '{print $6}')
pid=$(echo $line | awk '{print $7}')
user=$(echo $line | awk '{print $1}')

grep -q "^${user}:" $EXCEPTIONLIST
if [ $? != 0 ]
then
if [ "$time" = "old" ]
then
(( time = $TIMEOUT + 1 ))
else
echo $time |grep -q "\."
if [ $? != 0 ]
then
time=$(echo $time|awk '{FS=":";print $1*60+$2}')
else
time=0
fi
fi
fi
#echo $time
if [ $time -gt $TIMEOUT ]
then
echo "$user:$time:$pid:Killed"

# Uncomment to do kill that PID
kill_pid $pid
else
echo "$user:$time:$pid:Untouched"
fi
done
peterchu
Super Advisor

Re: kill idle user

do I need to change the path for linux ? or any command need to be change for linux ? thx