Script to capture userids logged on & killing as well


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to capture userids logged on & killing as well
# 1  
Old 01-06-2010
Script to capture userids logged on & killing as well

Can someone help me with a script to capture the list of users logged on at a point of time, and if a particular user id say xyz exists, kill that process Id.
# 2  
Old 01-06-2010
You need use below commands to get your result.

Code:
who
ps -ef  |grep xyz

If you ask how, please do some research first.
# 3  
Old 01-06-2010
this is something that came into my mind before but i didnt seriously think about it.
"who -u" gives the users who logged into a system anytime. I tried to write one script now and then tested it, but as im only user logged in test server i couldnt kill my login pid, should try later Smilie

try this:

Code:
#!/bin/bash
who -u | /usr/xpg4/bin/awk '/SPECIFIC_USER_IP/ {gsub("^\(|\)$","",$8);print($0)}' OFS="\t" > users.txt
user_ip=`/usr/xpg4/bin/awk '{print($8)}' users.txt`
pid=`/usr/xpg4/bin/awk' {print($7)}' users.txt`
if [ -e "$user_ip" ]; then
kill -9 $pid
fi

Note: you can use the user name in 2nd column instead of ip address in 8th column of "who -u" output
Code:
shell>who -u
root       pts/1        Jan  6 23:55   .     9492       (192.168.1.24)

Regards

Last edited by EAGL€; 01-06-2010 at 07:56 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

How to Dynamically Pass Parameter to plsql Function & Capture its Output Value in a Shell Variable?

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: 2. Relevant commands, code, scripts, algorithms: #! /bin/ksh v="ORG_ID" ... (2 Replies)
Discussion started by: sujitdas2104
2 Replies

2. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

3. Shell Programming and Scripting

How to capture last 15mins data logged from server.log file?

Below is Script to scan the errorlist file (errorlist file includes a list of errors) with sererv.log file (sererv.log file should contain data of recent 15mins ) but my requirement is I should get the recent logs i.e. cmd to capture only recent 15mins data logged from sererv.log file then scan... (3 Replies)
Discussion started by: manohar2013
3 Replies

4. Shell Programming and Scripting

Date capture & filter

Dear All, I am capturing system date and creating the file by using that time stamp, file is getting appended with checks of application & database check logs. But when the date is in between 1 to 9 both inclusive, it appends a single space to file name but after 9th it works fine. ... (5 Replies)
Discussion started by: pradeep84in
5 Replies

5. Shell Programming and Scripting

Finding the age of a unix process, killing old processes, killing zombie processes

I had issues with processes locking up. This script checks for processes and kills them if they are older than a certain time. Its uses some functions you'll need to define or remove, like slog() which I use for logging, and is_running() which checks if this script is already running so you can... (0 Replies)
Discussion started by: sukerman
0 Replies

6. Shell Programming and Scripting

Killing a shell script

Hi, If I have a large shell script running as root, say for example like one that copies a ton of files, how would I kill the shell script and any processes that it created? Thanks (7 Replies)
Discussion started by: pcwiz
7 Replies

7. Shell Programming and Scripting

Script to identify logged users & commands executed

Hi All, I am trying to write a script to get the user information & the command executed. I tried something like this : w | sort | awk '{print$5$6$7}' My requirement is to identify the users who execute the same command at same time. I need the user name & the... (2 Replies)
Discussion started by: vijayarajvp
2 Replies

8. Shell Programming and Scripting

how to grep sort userids

hello folks i have a file that have data like /test/aa/123 /test/aa/xyz /test/bb/xyz /test/bb/123 in above lines i just wants to grep "aa" and "bb". Thanks, Bash (4 Replies)
Discussion started by: learnbash
4 Replies

9. Shell Programming and Scripting

Grep userids

Hey, what's the best way to use grep to list all userid's on the system that do not contain the "." character (period). Also, could I edit the same command to list all the userid's on the system that are 10 or more characters in length. Thanks, I'm not that familiar with grep, but I know it can do... (1 Reply)
Discussion started by: raidkridley
1 Replies

10. UNIX for Dummies Questions & Answers

Will userids make a difference in performance?

I have nearly 10 users who login into the HP server (D series, HP UX 10.20) with the same UNIX user name, "liveuser", and they start the UNIX based transactions. If I create separate UNIX user-ids for all the 10, will the system performance improve? (1 Reply)
Discussion started by: augustinep
1 Replies
Login or Register to Ask a Question