How to kill process after x idle min?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to kill process after x idle min?
# 1  
Old 02-24-2009
CPU & Memory How to kill process after x idle min?

I need a script to kill those process id whose idle time is more than 30min
plz help me
# 2  
Old 02-24-2009
# 3  
Old 02-24-2009
[[ -z "$1" ]] && echo "Usage: $0 pid" && exit 1

[[ "$1" != +([0-9]) ]] && echo "$1 is not a valid pid" && exit 1

PID="$1"
W=$(which w)
PS=$(which ps)
SED=$(which sed)
AWK=$(which awk)

TTY=$($PS -o tty4 $PID)
TTNo=$(echo "$TTY" | $SED -e '/TTY/d')

TIME=$($W | $SED -n -e "/pts\/$TTNo/p" | $AWK '{ print $5 }')

echo $PID has been idle for $TIME

[[ $TIME = *day* ]] && echo "Killing $PID" && kill -9 $PID && exit 0

IDLE=${TIME%%:*}

[[ $IDLE -gt 30 ]] && echo "Killing $PID" && kill -9 $PID && exit 0


it doesn't work.....
# 4  
Old 02-25-2009
plz ne one help me!!
I need a script to kill those process id whose idle time is more than 30min
plz help me
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Idle command to kill the process running n unx box machine

Hi Team , I have one process named as cec_analysiseool that is running on unix box machine now i want to kill this process so please advise what will be the ideal command to kill this , what i have tried is :confused: kill -9 `ps -ef | grep cec_analysiseool | grep -v grep | awk '{print $2}'` (2 Replies)
Discussion started by: unclesamm
2 Replies

2. Shell Programming and Scripting

Kill idle Process using a script

Hi, I need a script that can automatically kill all processes named "webrepn" and "webrebw" if idle for more than 30 minutes. Then I will have a Cron Job to run the script every night or 2-3 times a day depends on how this script helps. Right now, I run "ps -ef | grep webrebn" and "kill -9... (7 Replies)
Discussion started by: MaggieL
7 Replies

3. Shell Programming and Scripting

User idle time and kill

Hello.. I have many sleepy users on my Solaris box and need to kill them if they are idle for more than 45 minutes for example...I know who -u gives and the idle time but unable to make a awk line to get the condition perfect. Please help...:wall: (9 Replies)
Discussion started by: wimaxpole
9 Replies

4. Shell Programming and Scripting

Write a scripts to kill idle user for 60 min. & email user list to admin in text file

Folks, I have written one script for following condition by referring some of online post in this forum. Please correct it if I'm missing something in it. (OS: AIX 5.3) List the idle user. (I used whoidle command to list first 15 user and get username, idle time, pid and login time).... (4 Replies)
Discussion started by: sumit30
4 Replies

5. Solaris

Kill idle dt session

Hi, i need to kill the idle dt sessions through script, can anyone tell me how to do? RJS (2 Replies)
Discussion started by: rajasekg
2 Replies

6. AIX

Kill IDLE Process using script !!!

Dear Friends , I am using DB2 database in AIX 5.3 server . In my server some IDLE process are generated after several times which I need to kill it manually each and every time . The process I query like following : root@bagpuss $ ps auxw|sort -r +3|head -10 USER PID %CPU %MEM ... (3 Replies)
Discussion started by: shipon_97
3 Replies

7. Shell Programming and Scripting

Perl : Kill process within 5 min

From a perl script , How can I monitor a PS which I activated and kill it within 5 minutes in case it didn't complete its tasks.:confused: (2 Replies)
Discussion started by: Alalush
2 Replies

8. HP-UX

kill idle users

Hi, In my network we uses the NetTerm program to connect us to HP-UX 10.x server from windows workstations, but in some cases the user doesn't logout and close it by window's x button. The problem is that in HP-UX the user and all his tasks remain active and when he enter again HP-UX creates a... (12 Replies)
Discussion started by: efrenba
12 Replies

9. HP-UX

Is there a script available to kill Idle users

My max user parm is set to 1050. I'm currently at 1038 this is causing major slow downs on the server. I looking for a way log off "idle" user logins with out having to do it individually. :confused: (5 Replies)
Discussion started by: rfmurphy_6
5 Replies

10. SCO

Identifiy and Kill Idle Unix(SCO) Process called externally

Hi, Please let us know of any possiblity of identifying and killing unix proces invoked externally (by an external tool which does not create a session). 'who' command gives idle time of sessions. But what we are looking for is idle time of a process. 'ps' command gives the elapsed/running... (1 Reply)
Discussion started by: vbalajis
1 Replies
Login or Register to Ask a Question