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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Kill idle users over 60 min

Reply to Message Icon

Name: Hamim
Date: May 28, 2003 at 07:24:17 Pacific
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



Sponsored Link
Ads by Google

Response Number 1
Name: LANkrypt0
Date: May 28, 2003 at 11:52:50 Pacific
Reply:

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


0

Response Number 2
Name: hamim
Date: June 4, 2003 at 03:17:05 Pacific
Reply:


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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Kill idle users over 60 min

Kill idle login www.computing.net/answers/unix/kill-idle-login/2290.html

Problem with idle user www.computing.net/answers/unix/problem-with-idle-user/3983.html

How to kill idel user www.computing.net/answers/unix/how-to-kill-idel-user/4678.html