User idle time and kill


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting User idle time and kill
# 1  
Old 06-28-2011
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...Smilie
# 2  
Old 06-28-2011
post the who -u output ( atleast two lines) and which column you are interested in ?
This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 06-28-2011
the below line will retain only the present day tty sessions.. else if you need to retain only <45 mins sessions, let us know.

Code:
$ who -u | grep -v "`date +%b" "%d`" | awk ' { print "kill -9 "$7 } ' | sh

This User Gave Thanks to jayan_jay For This Post:
# 4  
Old 06-28-2011
Thanks for your replies...

Code:
test1      pts/2        Jun 28 11:10  0:21  14041     
test2      pts/3        Jun 28 11:10  0:20  14055       
test3      pts/4        Jun 28 11:11  0:20  14073      
root       pts/5        Jun 28 11:11   .    14092

In the above, filed #6 shows users are idling 0:21 and 0:20 minutes, I need to kill them if the go above 45 minutes but except root user. Thanks...

Last edited by Franklin52; 06-28-2011 at 07:39 AM.. Reason: Please use code tags for code and data samples, thank you
# 5  
Old 06-28-2011
Code:
 
for in in `who -u | nawk ' ! /^root/ { if(substr($6,length($6)-1,length($6)) > 20) printf ("%s ",$1) }'`
do
 #kill here
done

This User Gave Thanks to itkamaraj For This Post:
# 6  
Old 06-28-2011
Thanks very much.. wonder full script.
# 7  
Old 06-28-2011
you need to change the condition

Code:
 
 > 20  to > 45

This User Gave Thanks to itkamaraj For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. Shell Programming and Scripting

Kill idle script is killing unnecessarly

Hi All,I have a problem with my kill idle script.my script is supposed to kill the user sessions which are idle for more than 2 hours.But is is killing the sessions which are idle for less than 2 hrs also.I dont know the exact time after which the script is killing,but it is less than 2 hours i am... (3 Replies)
Discussion started by: prabhu_kumar
3 Replies

5. 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

6. UNIX for Advanced & Expert Users

To find idle time of a user

Hi All I need to find the idle time of a user... but my OS seems to be not supporting finger $ finger -sh: finger: command not found I need to find the idle time and perform some other operations... So is there any other way i can find the idle time of a user... $ uname -a... (2 Replies)
Discussion started by: Whiteboard
2 Replies

7. Shell Programming and Scripting

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 (3 Replies)
Discussion started by: salil2012
3 Replies

8. Shell Programming and Scripting

User Idle Time

Does anyone know how do you determine the user idle time of stdin in order to log the user out for being idle too long. I would like to write a c program to do this but I it is not clear upon how to determine idle time from keyboard input. (9 Replies)
Discussion started by: cpaquette
9 Replies

9. 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

10. 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
Login or Register to Ask a Question