Script to AutoKill PIDs of LOGED in Active User


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to AutoKill PIDs of LOGED in Active User
# 1  
Old 11-26-2007
Question Script to AutoKill PIDs of LOGED in Active User

Smilie Hi
i am trying to make a script through which i can get the total number of User and their PID after that kill all Users except the one by which i am currently logged in. (i m using SCO UNIX 5.06)

# id of current usre < total number of current user
USR=`who -u |wc -l`

# id of current user
IAM=`who -u -m |cut -b 43-49 |cut -d " " -f1,2,3,4,5`

# name of current user
IM=`who am i | cut -d" " -f1`

# Process ids of all users
PUID=who -u |grep $IM$ |cut -b 43-49 |cut -d " " -f1,2,3,4,5

# Icremental variable

KILPID=0

# This loop will run until the KLPID VAR not equal to the number of user.
while test ${KILPID} -le $USR
do
if [ $IAM != $PUID]
then
kill -9 $PUID
fi
KILPID=`expr ${KILPID} + 1`
done

Last edited by aafflatoon; 11-27-2007 at 01:38 AM..
# 2  
Old 11-26-2007
Hi.
I would do the following instead:
Code:
MYTTY=$(tty | sed 's/\/dev\///')
kill $(who -u | grep -v "$MYTTY" | awk '{print $7}')

This will kill other users' sessions except your one. Though, this may not be what you want...

Besides,
Quote:
# Process ids of all users
PUID=who -u |grep $IM |cut -b 43-49 |cut -d " " -f1,2,3,4,5
Regards.

(I Forgot to mention I'm using AIX 5.2)

Last edited by grial; 11-26-2007 at 12:09 PM.. Reason: comment added
# 3  
Old 11-26-2007
Seeing as only root can kill other people's processes you are really saying kill everyone else except root, why not just take the machine down to single user level?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find number of ACTIVE SSH putty sessions, excluding where the user hopped on to a diff server

Hi - If iam logged on to server A, on 4 putty windows using SSH ... and out of these 4 logged-in sessions, in one of the sessions if i did SSH from server A to server B; i would now have 4 putty windows sessions ... of which 3 are actively logged on to Server A while 1 putty window is actively... (2 Replies)
Discussion started by: i4ismail
2 Replies

2. Shell Programming and Scripting

Active User List Script

Hello guys ! I tried a script to list all the active users in the current server in AIX who | grep '^user' this displays the entire line ... All I need is only the user list I found a command for linux using grep -o word grep -o was not recognized in AIX Can you guys help me out ? Use... (2 Replies)
Discussion started by: varun aravinth
2 Replies

3. Solaris

Configure Solaris to accept Active Directory user logins

Is it possible to configure a Solaris server to authenticate users against an Active Directory server when logging in via ssh? I've seen some docs out there, I've followed their instructions, but it does not work. And I'm beginning to wonder if it is possible or even supported by Oracle. The... (2 Replies)
Discussion started by: BG_JrAdmin
2 Replies

4. Homework & Coursework Questions

script to write PIDs to a file

script to write PIDs to a file Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: write a script that writes the PID of 2 different processes to a file every... (1 Reply)
Discussion started by: navlelo
1 Replies

5. AIX

command to kill all loged in users

Guy's I'm looking for command to kill all the loged in users in AIX server Is there specific command can help us to kill any loged in users I have this command who -u it'll show me the process ID of all the users but I want command to kill all the users including to root without... (1 Reply)
Discussion started by: Mr.AIX
1 Replies

6. Shell Programming and Scripting

Shell Script for PIDs

I am trying to write a Shell script wherein the shell needs to read a list of PID in the File $stat/bin/Process and compare it to the PID of the processes running on a server. Also the script should return KO(not OK) with corresponding label :- a) When an environmental variable not... (2 Replies)
Discussion started by: marconi
2 Replies

7. Shell Programming and Scripting

users who loged within 5 minutes

Hi i want to display the users who loged in within 5 minutes in unix by roshni (3 Replies)
Discussion started by: roshni
3 Replies

8. Post Here to Contact Site Administrators and Moderators

Then user who loged in befor 5 minutes

hi i am a student, i want to know how to display the users who loged in before 5 minutes, in uinx pls reply me immediately (0 Replies)
Discussion started by: roshni
0 Replies

9. Shell Programming and Scripting

Script to count unique number of user loged in

Hi all, I am taking my first course in unix and having some problems. I would line to create a scrip that does the following: 1) will tell me the number of users logged in. If a user is logged more than once just count it only ones. 2) want to be able to display the number of users that... (1 Reply)
Discussion started by: elchalateco
1 Replies
Login or Register to Ask a Question