<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: kill user in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368967#M13819</link>
    <description>We can control the user login based on the script as,&lt;BR /&gt;&lt;BR /&gt;for user in `who -u | awk '{ print $6":"$7 }' | grep -v "\."| awk -F : '{ print ($1*60)+$2":"$3 }'`&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;  time=`echo $user | awk '{ print $1 }'`&lt;BR /&gt;  pid=`echo $user | awk '{ print $2 }'`&lt;BR /&gt;&lt;BR /&gt;  if [[ $time -gt 30 ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "Login denied because of reaching user max. limit 300"&lt;BR /&gt;    kill -9 $pid&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;You can control this in 2 ways as,&lt;BR /&gt;&lt;BR /&gt; 1&amp;gt; Put this script in /etc/profile so that new user login is denied to log&lt;BR /&gt;&lt;BR /&gt; 2&amp;gt; Put this script in cron to automate in the correspoding timings.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Muthu&lt;BR /&gt;  &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 31 Aug 2004 23:10:42 GMT</pubDate>
    <dc:creator>Muthukumar_5</dc:creator>
    <dc:date>2004-08-31T23:10:42Z</dc:date>
    <item>
      <title>kill user</title>
      <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368963#M13815</link>
      <description>We have about 300 users on the Linux system , and due to the license is limit , we  only allow 200 users logins at the same time , but the total of logins always over 200 , so I want to kill the users who idle for a specific time ( eg . 30 minuts ) , i tried to use TMOUT , but it seems not good as we have many users in the system , is there any script can kill the idle users ? thx in advance.&lt;BR /&gt;</description>
      <pubDate>Tue, 31 Aug 2004 08:54:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368963#M13815</guid>
      <dc:creator>peterchu</dc:creator>
      <dc:date>2004-08-31T08:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: kill user</title>
      <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368964#M13816</link>
      <description>TMOUT will not work on users with the application already open.&lt;BR /&gt;&lt;BR /&gt;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:&lt;BR /&gt;&lt;BR /&gt;root su - to app owner user runs utility, makes a list of users to kill. End of script exits.&lt;BR /&gt;&lt;BR /&gt;Then root processes the list with kill -9 commands.&lt;BR /&gt;&lt;BR /&gt;To be more specific, I need to know the app.&lt;BR /&gt;&lt;BR /&gt;SEP&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 31 Aug 2004 08:59:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368964#M13816</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2004-08-31T08:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: kill user</title>
      <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368965#M13817</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;'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.,&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Tue, 31 Aug 2004 09:00:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368965#M13817</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2004-08-31T09:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: kill user</title>
      <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368966#M13818</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;try the following&lt;BR /&gt;&lt;BR /&gt;for i in `who -u|awk '$6&amp;gt;30{print $7}'`&lt;BR /&gt;do&lt;BR /&gt;kill (-9) $i&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This should kill all user procs which are idle for more than 30 minutes&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Franky</description>
      <pubDate>Tue, 31 Aug 2004 09:25:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368966#M13818</guid>
      <dc:creator>Franky_1</dc:creator>
      <dc:date>2004-08-31T09:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: kill user</title>
      <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368967#M13819</link>
      <description>We can control the user login based on the script as,&lt;BR /&gt;&lt;BR /&gt;for user in `who -u | awk '{ print $6":"$7 }' | grep -v "\."| awk -F : '{ print ($1*60)+$2":"$3 }'`&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;  time=`echo $user | awk '{ print $1 }'`&lt;BR /&gt;  pid=`echo $user | awk '{ print $2 }'`&lt;BR /&gt;&lt;BR /&gt;  if [[ $time -gt 30 ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "Login denied because of reaching user max. limit 300"&lt;BR /&gt;    kill -9 $pid&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;You can control this in 2 ways as,&lt;BR /&gt;&lt;BR /&gt; 1&amp;gt; Put this script in /etc/profile so that new user login is denied to log&lt;BR /&gt;&lt;BR /&gt; 2&amp;gt; Put this script in cron to automate in the correspoding timings.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Muthu&lt;BR /&gt;  &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 31 Aug 2004 23:10:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368967#M13819</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-08-31T23:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: kill user</title>
      <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368968#M13820</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;if anyone could help you then please assign points&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Franky</description>
      <pubDate>Wed, 01 Sep 2004 03:18:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368968#M13820</guid>
      <dc:creator>Franky_1</dc:creator>
      <dc:date>2004-09-01T03:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: kill user</title>
      <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368969#M13821</link>
      <description>thx Muthukumar , I tried your script , it meet the requirement , but when I run it , it will display the below message , it seems can't kill the user yet , could suggest what is wrong ? thx.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# ./kill_user&lt;BR /&gt;./kill_user[5]: 90:27392:  not found.&lt;BR /&gt;./kill_user[5]: 407:17966:  not found.&lt;BR /&gt;./kill_user[5]: 209:21212:  not found.&lt;BR /&gt;./kill_user[5]: 114:18946:  not found.&lt;BR /&gt;./kill_user[5]: 38:21098:  not found.&lt;BR /&gt;./kill_user[5]: 38:21119:  not found.&lt;BR /&gt;./kill_user[5]: 379:22933:  not found.&lt;BR /&gt;./kill_user[5]: 158:21181:  not found.&lt;BR /&gt;./kill_user[5]: 455:21627:  not found.&lt;BR /&gt;./kill_user[5]: 60:22365:  not found.&lt;BR /&gt;./kill_user[5]: 24:25634:  not found.&lt;BR /&gt;./kill_user[5]: 11:28360:  not found.</description>
      <pubDate>Wed, 01 Sep 2004 04:39:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368969#M13821</guid>
      <dc:creator>peterchu</dc:creator>
      <dc:date>2004-09-01T04:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: kill user</title>
      <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368970#M13822</link>
      <description>It seems the two awk lines for user and pid are missing the '-F :' arguments to set the field seperator.</description>
      <pubDate>Wed, 01 Sep 2004 07:07:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368970#M13822</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2004-09-01T07:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: kill user</title>
      <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368971#M13823</link>
      <description>thx replies, but I am not familiar with the script writing , I tried to modify the script ( add -F : )as below , but still hv error when run the script , please help to point out what I am wrong , thx in advance.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;time=`echo $user | awk -F : '{ print $1 }'`&lt;BR /&gt;pid =`echo $user | awk -F : '{ print $2 }'`&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;########### Error #################&lt;BR /&gt;&lt;BR /&gt;real        0.0&lt;BR /&gt;user        0.0&lt;BR /&gt;sys         0.0&lt;BR /&gt;./aa[5]: pid:  not found.&lt;BR /&gt;No such file or directory: =&lt;BR /&gt;&lt;BR /&gt;real        0.0&lt;BR /&gt;user        0.0&lt;BR /&gt;sys         0.0&lt;BR /&gt;./aa[5]: pid:  not found.&lt;BR /&gt;No such file or directory: =&lt;BR /&gt;&lt;BR /&gt;real        0.0&lt;BR /&gt;user        0.0&lt;BR /&gt;sys         0.0&lt;BR /&gt;./aa[5]: pid:  not found.</description>
      <pubDate>Wed, 01 Sep 2004 23:00:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368971#M13823</guid>
      <dc:creator>peterchu</dc:creator>
      <dc:date>2004-09-01T23:00:51Z</dc:date>
    </item>
    <item>
      <title>Re: kill user</title>
      <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368972#M13824</link>
      <description>Hai Peter,&lt;BR /&gt;&lt;BR /&gt;Check this one,&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;#killuser&lt;BR /&gt;set -x&lt;BR /&gt;for user in `who -u | awk '{ print $6":"$7 }' | grep -v "\."| awk -F : '{ print ($1*60)+$2":"$3 }'`&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;time=`echo $user | awk -F ":" '{ print $1 }'`&lt;BR /&gt;pid=`echo $user | awk -F ":" '{ print $2 }'`&lt;BR /&gt;&lt;BR /&gt;if [[ $time -gt 30 ]]&lt;BR /&gt;then&lt;BR /&gt;echo "Login denied because of reaching user max. limit 300"&lt;BR /&gt;kill -9 $pid&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;-----------&lt;BR /&gt;&lt;BR /&gt;# ksh killuser&lt;BR /&gt;It will give the debugging statements.&lt;BR /&gt;&lt;BR /&gt;Problem may be because of only -F :&lt;BR /&gt;&lt;BR /&gt;But &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;eal 0.0&lt;BR /&gt;user 0.0&lt;BR /&gt;sys 0.0&lt;BR /&gt;./aa[5]: pid: not found.&lt;BR /&gt;No such file or directory: =&lt;BR /&gt;&lt;BR /&gt;real 0.0&lt;BR /&gt;user 0.0&lt;BR /&gt;sys 0.0&lt;BR /&gt;./aa[5]: pid: not found.&lt;BR /&gt;No such file or directory: =&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;say --&amp;gt;&lt;BR /&gt;&lt;BR /&gt;Did you change script contents or execute with time command ?!?&lt;BR /&gt;&lt;BR /&gt;It is good to have to know what did u try on that. and give the debug mode output.&lt;BR /&gt;&lt;BR /&gt;Note: I have test it is successfull doing</description>
      <pubDate>Wed, 01 Sep 2004 23:27:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368972#M13824</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-09-01T23:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: kill user</title>
      <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368973#M13825</link>
      <description>Here is another way with perl. The script should print ps output of processes it would terminate. Examine the output first and if ok, uncomment line with /usr/bin/kill. Script ignores idle CDE sessions, console logins and  root processes.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt; &lt;BR /&gt;# Idle limit in minutes&lt;BR /&gt;$idle_lim = 30;&lt;BR /&gt; &lt;BR /&gt;@w = `/usr/bin/w -h`;&lt;BR /&gt;chomp @w;&lt;BR /&gt; &lt;BR /&gt;$w1 = 29;&lt;BR /&gt;$w2 = 22;&lt;BR /&gt; &lt;BR /&gt;for (@w) {&lt;BR /&gt;        ($a, $b, $what) = /^(.{$w1})(.{$w2})(.*)$/;&lt;BR /&gt;        ($user, $tty, $login_at) = split(" ", $a);&lt;BR /&gt;        ($idle, $jcpu, $pcpu) = split(" ", $b);&lt;BR /&gt;        if ($idle =~ /:/) {&lt;BR /&gt;                ($idle_h, $idle_m) = split(/:/, $idle);&lt;BR /&gt;                $idle = $idle_h * 60 + $idle_m;&lt;BR /&gt;        }&lt;BR /&gt;        if ($idle &amp;gt; $idle_lim and $tty =~ /^[pt]/ and $user ne "root") {&lt;BR /&gt;                print "$user at $tty idle for $idle minutes\n";&lt;BR /&gt;                @pids = `UNIX95= /usr/bin/ps -t $tty -o pid=`;&lt;BR /&gt;                chomp @pids;&lt;BR /&gt;                for $pid (@pids) {&lt;BR /&gt;                        system("/usr/bin/ps -fp $pid | grep -v PID");&lt;BR /&gt;                        # system("/usr/bin/kill $pid");&lt;BR /&gt;                }&lt;BR /&gt;        }&lt;BR /&gt;}</description>
      <pubDate>Thu, 02 Sep 2004 01:00:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368973#M13825</guid>
      <dc:creator>Ermin Borovac</dc:creator>
      <dc:date>2004-09-02T01:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: kill user</title>
      <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368974#M13826</link>
      <description>thx replies,&lt;BR /&gt;&lt;BR /&gt;hi Muthukumar , &lt;BR /&gt;&lt;BR /&gt;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.</description>
      <pubDate>Thu, 02 Sep 2004 02:33:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368974#M13826</guid>
      <dc:creator>peterchu</dc:creator>
      <dc:date>2004-09-02T02:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: kill user</title>
      <link>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368975#M13827</link>
      <description>Hai,&lt;BR /&gt;&lt;BR /&gt; We can sepate special users with the following script as,&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;# killuser.ksh&lt;BR /&gt;set -x&lt;BR /&gt;&lt;BR /&gt;# Enter the specific users&lt;BR /&gt;SPL_USER=""&lt;BR /&gt;&lt;BR /&gt;######### Script starts now ##########&lt;BR /&gt;set -A USER_ARR $SPL_USER&lt;BR /&gt;&lt;BR /&gt;set -A USER_NAME $(who -R | awk '{ print $1 }')&lt;BR /&gt;set -A PID_ARR $(who -Ru | awk '{ print $7 }')&lt;BR /&gt;set -A IP_ARR $(who -Ru | awk '{ print $8 }')&lt;BR /&gt;set -A TIME_ARR $(who -Ru | awk '{ print $6 }' |  grep -v "\."| awk -F : '{ print ($1*60)+$2 }')&lt;BR /&gt;&lt;BR /&gt;#######################################&lt;BR /&gt;&lt;BR /&gt;index=0&lt;BR /&gt;&lt;BR /&gt;while [[ $index -lt ${#USER_NAME[*]} ]]&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;  loop=0&lt;BR /&gt;  while [[ $loop -lt ${#SPL_USER[*]} ]]&lt;BR /&gt;  do&lt;BR /&gt;  &lt;BR /&gt;    if [[ "${SPL_USER[$loop]}" != "${USER_NAME[*]}" ]]&lt;BR /&gt;    then&lt;BR /&gt;      &lt;BR /&gt;      if [[ ${TIME_ARR[$index]} -gt 30 ]]&lt;BR /&gt;      then&lt;BR /&gt;       &lt;BR /&gt;        echo "Warning: Login denied because of reaching user max. limit 300"&lt;BR /&gt;        # More contact informations in echo statements as your mail-ID too&lt;BR /&gt; kill -9 ${PID_ARR[$index]}&lt;BR /&gt; &lt;BR /&gt; # You can add one more functionality as, make a mail&lt;BR /&gt; # mailx -s System usage ${USER_NAME}@yourdomain.com messages&lt;BR /&gt; &lt;BR /&gt;      fi&lt;BR /&gt;      &lt;BR /&gt;     fi&lt;BR /&gt;   &lt;BR /&gt;   let loop=loop+1&lt;BR /&gt;   done&lt;BR /&gt;  &lt;BR /&gt;  let index=index+1&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;where you have to fill in the script as,&lt;BR /&gt;# Enter the specific users&lt;BR /&gt;SPL_USER="test adm muthu"&lt;BR /&gt;&lt;BR /&gt;space is needed between users.&lt;BR /&gt;&lt;BR /&gt;Try to test it with out kill then start to use with kill command.&lt;BR /&gt;&lt;BR /&gt;If you need more enhancement let me know.&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;&lt;BR /&gt;And Lot of responder(s) replied questions. So give reward by assigning points :-)&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Muthu&lt;BR /&gt;</description>
      <pubDate>Thu, 02 Sep 2004 04:07:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/kill-user/m-p/3368975#M13827</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-09-02T04:07:22Z</dc:date>
    </item>
  </channel>
</rss>

