- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- kill 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
08-31-2004 01:54 AM
08-31-2004 01:54 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2004 01:59 AM
08-31-2004 01:59 AM
Re: kill user
What you can do is process the output of an application monitor through a script. If you have an application monitor that will show idle users you can do this:
root su - to app owner user runs utility, makes a list of users to kill. End of script exits.
Then root processes the list with kill -9 commands.
To be more specific, I need to know the app.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2004 02:00 AM
08-31-2004 02:00 AM
Solution'w' will show the idle time as the 4th column for each user. You should be able to script yourself to kill the users the have more than 30 mins of idle time. You may have to spend sometime on it as you may have to convert days, hours, mins etc.,
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2004 02:25 AM
08-31-2004 02:25 AM
Re: kill user
try the following
for i in `who -u|awk '$6>30{print $7}'`
do
kill (-9) $i
done
This should kill all user procs which are idle for more than 30 minutes
Regards
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2004 04:10 PM
08-31-2004 04:10 PM
Re: kill user
for user in `who -u | awk '{ print $6":"$7 }' | grep -v "\."| awk -F : '{ print ($1*60)+$2":"$3 }'`
do
time=`echo $user | awk '{ print $1 }'`
pid=`echo $user | awk '{ print $2 }'`
if [[ $time -gt 30 ]]
then
echo "Login denied because of reaching user max. limit 300"
kill -9 $pid
fi
done
You can control this in 2 ways as,
1> Put this script in /etc/profile so that new user login is denied to log
2> Put this script in cron to automate in the correspoding timings.
Regards
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2004 08:18 PM
08-31-2004 08:18 PM
Re: kill user
if anyone could help you then please assign points
Regards
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2004 09:39 PM
08-31-2004 09:39 PM
Re: kill user
# ./kill_user
./kill_user[5]: 90:27392: not found.
./kill_user[5]: 407:17966: not found.
./kill_user[5]: 209:21212: not found.
./kill_user[5]: 114:18946: not found.
./kill_user[5]: 38:21098: not found.
./kill_user[5]: 38:21119: not found.
./kill_user[5]: 379:22933: not found.
./kill_user[5]: 158:21181: not found.
./kill_user[5]: 455:21627: not found.
./kill_user[5]: 60:22365: not found.
./kill_user[5]: 24:25634: not found.
./kill_user[5]: 11:28360: not found.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2004 12:07 AM
09-01-2004 12:07 AM
Re: kill user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2004 04:00 PM
09-01-2004 04:00 PM
Re: kill user
time=`echo $user | awk -F : '{ print $1 }'`
pid =`echo $user | awk -F : '{ print $2 }'`
########### Error #################
real 0.0
user 0.0
sys 0.0
./aa[5]: pid: not found.
No such file or directory: =
real 0.0
user 0.0
sys 0.0
./aa[5]: pid: not found.
No such file or directory: =
real 0.0
user 0.0
sys 0.0
./aa[5]: pid: not found.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2004 04:27 PM
09-01-2004 04:27 PM
Re: kill user
Check this one,
#!/usr/bin/ksh
#killuser
set -x
for user in `who -u | awk '{ print $6":"$7 }' | grep -v "\."| awk -F : '{ print ($1*60)+$2":"$3 }'`
do
time=`echo $user | awk -F ":" '{ print $1 }'`
pid=`echo $user | awk -F ":" '{ print $2 }'`
if [[ $time -gt 30 ]]
then
echo "Login denied because of reaching user max. limit 300"
kill -9 $pid
fi
done
-----------
# ksh killuser
It will give the debugging statements.
Problem may be because of only -F :
But
eal 0.0
user 0.0
sys 0.0
./aa[5]: pid: not found.
No such file or directory: =
real 0.0
user 0.0
sys 0.0
./aa[5]: pid: not found.
No such file or directory: =
say -->
Did you change script contents or execute with time command ?!?
It is good to have to know what did u try on that. and give the debug mode output.
Note: I have test it is successfull doing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2004 06:00 PM
09-01-2004 06:00 PM
Re: kill user
#!/usr/bin/perl
# Idle limit in minutes
$idle_lim = 30;
@w = `/usr/bin/w -h`;
chomp @w;
$w1 = 29;
$w2 = 22;
for (@w) {
($a, $b, $what) = /^(.{$w1})(.{$w2})(.*)$/;
($user, $tty, $login_at) = split(" ", $a);
($idle, $jcpu, $pcpu) = split(" ", $b);
if ($idle =~ /:/) {
($idle_h, $idle_m) = split(/:/, $idle);
$idle = $idle_h * 60 + $idle_m;
}
if ($idle > $idle_lim and $tty =~ /^[pt]/ and $user ne "root") {
print "$user at $tty idle for $idle minutes\n";
@pids = `UNIX95= /usr/bin/ps -t $tty -o pid=`;
chomp @pids;
for $pid (@pids) {
system("/usr/bin/ps -fp $pid | grep -v PID");
# system("/usr/bin/kill $pid");
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2004 07:33 PM
09-01-2004 07:33 PM
Re: kill user
hi Muthukumar ,
I tried your script , it work fine , but if I want to have one more requiremnet , I want to ignore to kill a list of users ( eg. senior staffs , EDP staffs and some special users ) , what can I do ? thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2004 09:07 PM
09-01-2004 09:07 PM
Re: kill user
We can sepate special users with the following script as,
#!/usr/bin/ksh
# killuser.ksh
set -x
# Enter the specific users
SPL_USER=""
######### Script starts now ##########
set -A USER_ARR $SPL_USER
set -A USER_NAME $(who -R | awk '{ print $1 }')
set -A PID_ARR $(who -Ru | awk '{ print $7 }')
set -A IP_ARR $(who -Ru | awk '{ print $8 }')
set -A TIME_ARR $(who -Ru | awk '{ print $6 }' | grep -v "\."| awk -F : '{ print ($1*60)+$2 }')
#######################################
index=0
while [[ $index -lt ${#USER_NAME[*]} ]]
do
loop=0
while [[ $loop -lt ${#SPL_USER[*]} ]]
do
if [[ "${SPL_USER[$loop]}" != "${USER_NAME[*]}" ]]
then
if [[ ${TIME_ARR[$index]} -gt 30 ]]
then
echo "Warning: Login denied because of reaching user max. limit 300"
# More contact informations in echo statements as your mail-ID too
kill -9 ${PID_ARR[$index]}
# You can add one more functionality as, make a mail
# mailx -s System usage ${USER_NAME}@yourdomain.com messages
fi
fi
let loop=loop+1
done
let index=index+1
done
where you have to fill in the script as,
# Enter the specific users
SPL_USER="test adm muthu"
space is needed between users.
Try to test it with out kill then start to use with kill command.
If you need more enhancement let me know.
HTH.
And Lot of responder(s) replied questions. So give reward by assigning points :-)
Regards
Muthu