Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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
donebasically 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

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

![]() |
![]() |
![]() |

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