- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: kill idle user
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2004 04:43 PM
10-15-2004 04:43 PM
for x in ` who -u |awk ........ `
do
idleuser = ......
if [[ ...... ]]
then
kill $idleuser
fi
done
If I want to add a user list so that the user in the list will be be killed by the script , could suggest how to modify the script ? thx.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2004 06:13 PM
10-15-2004 06:13 PM
SolutionHow are you getting the idle user?
To basically read from a file you can use either 'for' or 'while'. There are otherways too. With 'for'
for user in $(cat user_list)
do
idleuser=...
..
done
With 'while'
while read user
do
idleuser=...
...
done < user_list
The above was assuming that the users are speicified with one user per line.
If you post your complete script, then it will be much easier for us to suggest working solutions.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2004 06:14 PM
10-15-2004 06:14 PM
Re: kill idle user
I am able to under stand whats is your exact requirement any how go through the below script
collect all the users inthe system in to file say usrlst
cut -f1 -d : /etc/passwd > usrlst
for i in `cat usrlst`
do
ps $i |cut -f1 -d' ' | fuser -k
done
this will kill all the users those logged in the system . .if you want to modify usrlist you can change the users in the list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2004 06:22 PM
10-15-2004 06:22 PM
Re: kill idle user
May be I state my requirement more clearly , I want to kill the idle user but ignore to kill some user who are in A/C , EDP and Engineer department , what can I do ? thx.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2004 06:54 PM
10-15-2004 06:54 PM
Re: kill idle user
Then you have to somehow identify them by something. Say you add them all to a list say 'excludeusers.list' in the following format.
user1:Finance
user2:Engineering
user3:Finance
user4:Finance
etc.,
Then do the following
for x in `who -u|awk ...` #<-- I assume you are getting the user here"
do
grep -q "^${x}:" excludeusers.list
if [ $? != 0 ]
then
idleuser="
..
..
if [[ ...... ]]
then
kill $idleuser
fi
fi
done
Again, unless you post your exact script, these solutions may not work because we don't know how your script is gathering the data.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2004 09:10 PM
10-15-2004 09:10 PM
Re: kill idle user
the bwlow is my script , could suggest how to modify it ? thx
for x in `who -u | awk '{ print $6":"$7 }' | grep -v "\."| awk -F : '{ print
($1*60)+$2":"$3 }'`
do
time=`echo $x | awk -F ":" '{ print $1 }'`
pid=`echo $x | awk -F ":" '{ print $2 }'`
if [[ $time -gt 120 ]]
then
kill -1 $pid
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2004 02:23 AM
10-16-2004 02:23 AM
Re: kill idle user
#!/bin/sh
who -u | while read line
do
time=`echo $line | grep -v "/." | awk '{ split($6,a,":"); print (a[1]*60)+a[2] }'`
pid=`echo $line | awk '{ print $7 }'`
if [[ $time -gt 120 ]]
then
kill -1 $pid
fi
done
It will kill all session's ID with is idle more than 120 seconds there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2004 02:28 AM
10-16-2004 02:28 AM
Re: kill idle user
Remove grep -v "/." there and try as
#!/bin/sh
set -x
who -u | while read line
do
time=`echo $line | awk '{ split($6,a,":"); print (a[1]*60)+a[2] }'`
pid=`echo $line | awk '{ print $7 }'`
if [[ $time -gt 120 ]]
then
kill -1 $pid
fi
done
It will work there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2004 02:43 AM
10-16-2004 02:43 AM
Re: kill idle user
We can not use for loop to get a line of words separated with ' ' ( space there ) then it will print word by word there.
Example:
for x `who -u`
do
echo $x
done
It will display word by word.
To do your requirement in one liner then,
kill -1 `who -u | awk '{ if ( $6 != "." ) { split($6,a,":");if ( a[1]*60+a[2]>=120) print $7 } }'`
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2004 03:48 AM
10-16-2004 03:48 AM
Re: kill idle user
If I want to exclude the users in some department , what can I do ? thx.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2004 01:56 PM
10-16-2004 01:56 PM
Re: kill idle user
There are couple of issues with the script.
1. The activity period in 'who -u' is displayed as 'old' if the inactivity is more than for 24 hrs.
2. Users that were not idle within the last minute will be displayed with a "." in their activity field.
Keeping in view the above, below is an easily understandable script. Create a file say /etc/exception.lst with the following format
user1:Engineering
user2:Finance
user3:Finanance
Try it as it is. Once you are satisfied, then remove the comment for the lines that has 'kill_pid' in the last 'if' statement.
-Sri
#!/usr/bin/sh
PATH=$PATH:/usr/bin:/usr/sbin:/usr/contrib/bin
TIMEOUT=120
EXCEPTIONLIST=/etc/exception.lst
touch $EXCEPTIONLIST
kill_pid()
{
PID=$1
kill -9 $PID
}
echo "User:Activity:PID:Status"
who -u | while read line
do
time=$(echo $line | awk '{print $6}')
pid=$(echo $line | awk '{print $7}')
user=$(echo $line | awk '{print $1}')
grep -q "^${user}:" $EXCEPTIONLIST
if [ $? != 0 ]
then
if [ "$time" = "old" ]
then
(( time = $TIMEOUT + 1 ))
else
echo $time |grep -q "\."
if [ $? != 0 ]
then
time=$(echo $time|awk '{FS=":";print $1*60+$2}')
else
time=0
fi
fi
fi
if [ $time -gt $TIMEOUT ]
then
echo "$user:$time:$pid:Killed"
#kill_pid $pid
else
echo "$user:$time:$pid:Untouched"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2004 10:03 PM
10-16-2004 10:03 PM
Re: kill idle user
#!/bin/sh
set -x
# Fill exception user list
USERLIST="test user peter"
set -A ARR $USERLIST
who -u | while read line
do
user=`echo $line | awk '{ print $1 }'
time=`echo $line | awk '{ split($6,a,":"); print (a[1]*60)+a[2] }'`
pid=`echo $line | awk '{ print $7 }'`
index=0
while [[ $index -lt ${#ARR[*]} ]]
do
if [[ $user != "${ARR[$index]}" ]]
then
if [[ $time -gt 120 ]]
then
kill -1 $pid
fi
fi
let index=index+1
done
Fill the needed user on USERLIST variable there.
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2004 03:31 PM
10-17-2004 03:31 PM
Re: kill idle user
I testing r method , but pop the below message
+ USERLIST=test user peter
+ set -A ARR test user peter
./ab: line 7: set: -A: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2004 02:19 AM
10-18-2004 02:19 AM
Re: kill idle user
Place in users .profile a timeout or
even in /etc/profile for system wide.
# Exit window on 15 min idle time
TMOUT=900
export TMOUT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2004 02:57 AM
10-18-2004 02:57 AM
Re: kill idle user
I have an exception list I look at before killing the user if idle. Idle is over 29 minuts. Over idle at over 39 minutes. And kill when over 59 minutes. Except if the user is on the list. I al so log the idle and kills.
Been using this for years.
idle_exception.list contains userID folloewd by a + sign like "metm+"
This may help you.
Marty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2004 01:16 AM
10-19-2004 01:16 AM
Re: kill idle user
I hv tried Sridhar Bhaskarla 's script ,
but have the below error when run it , could suggest how can I modify it ? thx.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2004 02:01 AM
10-19-2004 02:01 AM
Re: kill idle user
Try that as,
#!/usr/bin/sh
PATH=$PATH:/usr/bin:/usr/sbin:/usr/contrib/bin
TIMEOUT=120
EXCEPTIONLIST=/etc/exception.lst
touch $EXCEPTIONLIST
kill_pid()
{
PID=$1
kill -9 $PID
}
echo "User:Activity:PID:Status"
who -u | while read line
do
time=$(echo $line | awk '{print $6}')
pid=$(echo $line | awk '{print $7}')
user=$(echo $line | awk '{print $1}')
grep -q "^${user}:" $EXCEPTIONLIST
if [ $? != 0 ]
then
if [ "$time" = "old" ]
then
(( time = $TIMEOUT + 1 ))
else
echo $time |grep -q "\."
if [ $? != 0 ]
then
time=$(echo $time|awk '{FS=":";print $1*60+$2}')
else
time=0
fi
fi
fi
if [ $time -gt $TIMEOUT ]
then
echo "$user:$time:$pid:Killed"
# Uncomment to do kill that PID
#kill_pid $pid
else
echo "$user:$time:$pid:Untouched"
fi
done
HTH.
Regards
Muthu.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2004 02:20 AM
10-19-2004 02:20 AM
Re: kill idle user
Peter,
I have assigned points to 514 of 619 responses to my questions. Assign else more there. ;)
PS: 0 points to this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2004 02:06 PM
10-22-2004 02:06 PM
Re: kill idle user
I tried your script , it work fine at UNIX system , it fully meet the requirement , however , I also want to run it at linux , if I run it at RH linux , it will kill all the users right now ( even the user is processing sth ) , could suggest how can make it to make at linux ? thx.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2004 03:54 PM
10-24-2004 03:54 PM
Re: kill idle user
Use this script to on RH Linux versions. IT is working.
#!/bin/sh
# RH Linux idle user kill
# PATH
PATH=$PATH:/bin:/usr/bin:/usr/sbin:/usr/contrib/bin
TIMEOUT=120
EXCEPTIONLIST=./exception.lst
touch $EXCEPTIONLIST
if [[ ! -s $EXCEPTIONLIST ]]
then
echo "$EXCEPTIONLIST File is available with no users to avoid killing"
fi
kill_pid()
{
PID=$1
kill -9 $PID
}
echo "User:Activity:PID:Status"
who -u | while read line
do
time=$(echo $line | awk '{print $6}')
pid=$(echo $line | awk '{print $7}')
user=$(echo $line | awk '{print $1}')
grep -q "^${user}:" $EXCEPTIONLIST
if [ $? != 0 ]
then
if [ "$time" = "old" ]
then
(( time = $TIMEOUT + 1 ))
else
echo $time |grep -q "\."
if [ $? != 0 ]
then
time=$(echo $time|awk '{FS=":";print $1*60+$2}')
else
time=0
fi
fi
fi
if [ $time -gt $TIMEOUT ]
then
echo "$user:$time:$pid:Killed"
# Uncomment to do kill that PID
#kill_pid $pid
else
echo "$user:$time:$pid:Untouched"
fi
done
# Normal exit
exit 0
###
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2004 07:37 PM
10-27-2004 07:37 PM
Re: kill idle user
But I still have error when run it , could suggest what can I do ? thx.
kill_user: line 38: [: 175:: integer expression expected
edp_usr:175::12650:Untouched
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2004 07:46 PM
10-27-2004 07:46 PM
Re: kill idle user
I don't have a Linux system to test it. Can you post the output of 'who -u' on your linux box?. Obviously who -u is not giving the output in the format the script is excepted to.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2004 09:31 PM
10-27-2004 09:31 PM
Re: kill idle user
the who -u output is
edp_usrpts/13 Oct 28 14:30 . 7842 (192.168.1.12)
the output is the same as unix , thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2004 05:30 PM
11-02-2004 05:30 PM
Re: kill idle user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2004 01:54 PM
11-10-2004 01:54 PM