Computing.Net > Forums > Unix > Kill idle users over 60 min

Kill idle users over 60 min

Reply to Message Icon

Original Message
Name: Hamim
Date: May 28, 2003 at 07:24:17 Pacific
Subject: Kill idle users over 60 min
OS: ScoUnix ver5
CPU/Ram: Pentium2 D/proces & 512 m
Comment:

Hi,I need someone to please help me with a script to kill idle users,with no keyboard activity longer than 60 minutes.Icannot get piddle_p or anything else working off the net.
PLease help!!!
Thanks
Hamim


Report Offensive Message For Removal

Response Number 1
Name: LANkrypt0
Date: May 28, 2003 at 11:52:50 Pacific
Subject: Kill idle users over 60 min
Reply: (edit)

Fun little thing to write.
This script is written in KSH and uses grep/awk

#!/bin/ksh
idletimes=$(w | tail +3 | awk '{print $5}')

for numbers in $idletimes;do
if [[ $(echo "$numbers" | grep :) != "" || $(echo "$numbers" | grep "days") != "" ]];then
getline=$(w | tail +3 | grep $numbers)
user=$(echo $getline | awk '{print $1}')
processid=$(echo $getline | awk '{print $2}')
started=$(echo $getline | awk '{print $4}')
actprocess=$(ps -aux | grep $user | grep $processid | grep $started | awk '{print $2}')
kill $actprocess
fi
done

basically it does a who, puts the idle times in a list. Looks for either : (denotes hours) or days (denotes days) If it does not find either of those, it lets it go, if it does find them it gets their username, tty and start time.

It then does a ps -aux and searches by the username, tty and startime (to ensure you get the right process) it then kills that process.

I have no way of testing this unfortunately as I am not on my home machine. But it should work.

let me know


Report Offensive Follow Up For Removal

Response Number 2
Name: hamim
Date: June 4, 2003 at 03:17:05 Pacific
Subject: Kill idle users over 60 min
Reply: (edit)


Thanks,but I get an error :idle[10}: kill : bad argument count
Am I not supposed to grep for who -u instead of w
Please let me know
Thanks
Hamim


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Kill idle users over 60 min

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software