- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Kill all?
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
03-07-2001 05:34 AM
03-07-2001 05:34 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2001 05:41 AM
03-07-2001 05:41 AM
Re: Kill all?
It is possible, you can search at processes with ps -ef |grep user.
After that you can search in the /etc/group file for the special user.
Or you start the other way. first grep the group in the /etc/group, read those users of the group and grep in the proces list with this users.
marcel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2001 05:54 AM
03-07-2001 05:54 AM
Re: Kill all?
Perhaps you can try this little script :
ps -ef|grep ${1}|grep -v grep | sort | awk | '{print "kill -9 "$2}'> /usr/tmp/kill_em
chmod 744 /usr/tmp/kill_em
/usr/tmp/kill_em
ps -ef|grep ${1}
Only usable as superuser.
Rgds
Alexander M. Ermes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2001 07:30 AM
03-07-2001 07:30 AM
Re: Kill all?
kill -9 $ee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2001 07:36 AM
03-07-2001 07:36 AM
Re: Kill all?
ps -ef |grep username |awk '{print $2}' |xargs kill -9
=]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2001 08:10 AM
03-07-2001 08:10 AM
Re: Kill all?
I would suggest that you do a "gentle" kill first, followed by a "kill -9" after waiting a few seconds. This gives the processes being killed the ability to trap the termination signal and do any cleanup processing.
If you build the list of PIDs to kill into a variable as, for instance, suggested by Chris, then you can do something like:
kill $PIDLIST
sleep 5
kill -9 $PIDLIST 2> /dev/null
Redirecting the stderr of the second kill to /dev/null suppresses any (or all) "process does not exist" messages for those already dead.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2001 09:31 AM
03-07-2001 09:31 AM
Re: Kill all?
and have it kill all users from the seattle branch. So, I would name the script kill_seattle and list usernames to grep? Can you tell that I am inexperienced at this!?!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2001 10:20 AM
03-07-2001 10:20 AM
Re: Kill all?
Assuming you want to predefine the users in your branch, you could do something simple like this:
#!/usr/bin/sh
SEATTLE="-e usr1 -e usr2 -e usr3"
PIDLIST=`ps -ef|grep $WHO|grep -v grep|awk '{print $2}'`
kill $PIDLIST
sleep 5
kill -9 $PIDLIST
#.end.
The '-e' option allows multiple arguments; and the '-v' option filters out finding the 'grep' process you're running. Watch out for matches to users you don't want. For example, "usr" would match anything in the example script. You could always use regular expressions like:
[[:space:]]usr1[[:space:]]
in lieu of simply "usr1" if/as needed.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2001 10:28 AM
03-07-2001 10:28 AM
Re: Kill all?
What about:
kill `ps -u id1 id2 id3 | awk '{ print $1}'`
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2001 10:35 AM
03-07-2001 10:35 AM
Re: Kill all?
"ps -ef | grep user_to_kill" as selection base
might kill a process with the name /home/user_to_kill/job.sh although it is executed by user_never_to_be_killed !
May be some scripts should be adjusted ?
( ok, may be a rare case :-)
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2001 11:54 AM
03-07-2001 11:54 AM
Re: Kill all?
Here's another way to make the filtering of the 'ps' output more rigorous; choose the processes by user name and first issue a simple kill to allow the process to attempt to cleanup:
#!/usr/bin/sh
PIDLIST=``ps -ef|awk '$1~/^usr1$/||$1~/^usr2$/||$1~/^usr3$/ {print $2}'`
kill $PIDLIST
sleep 5
kill -9 $PIDLIST
#.end.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2001 04:31 PM
03-07-2001 04:31 PM
Re: Kill all?
#!/bin/sh
if [ "$2" = "" ]; then
SIG="-TERM"
else
SIG="$2"
fi
if [ "$1" = "" ]; then
echo "Usage: $0
exit
fi
WHO=`cat group | grep ^$1: | awk -F: '{ print $4 }' | sed s/,/\ /g`
for i in $WHO; do
kill $SIG `ps aux | grep $i | grep -v grep | awk '{ print $2 }'`
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2001 04:36 PM
03-07-2001 04:36 PM
Solution#!/bin/sh
if [ "$2" = "" ]; then
SIG="-TERM"
else
SIG="$2"
fi
if [ "$1" = "" ]; then
echo "Usage: $0
exit
fi
WHO=`cat /etc/group | grep ^$1: | awk -F: '{ print $4 }' | sed s/,/\ /g`
for i in $WHO; do
kill $SIG `ps -ef | grep $i | grep -v grep | awk '{ print $2 }'`
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2001 05:24 AM
03-08-2001 05:24 AM
Re: Kill all?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2001 06:17 AM
03-08-2001 06:17 AM
Re: Kill all?
your fine with the points, although if it is a real solution within one answer, it deserves at least 8 points (to show up the bunny).
If there is a second quote just for additional information, you could choose to add N/A (as you should do for this one), to keep your assignment statistics up to date.
But, if the additional information has good quality, it is also okay to assign additional points.
You will find several messages in this forum, which are over-pointed in my opinion. I.e the jokes that show up from time to time. But on the other hand, some of those are really good, so why not (I imagine this HP-McDonalds comparison a few days ago :~)
That was a well deserved 10 for Rick ....
Best Regards
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2001 10:05 AM
03-08-2001 10:05 AM
Re: Kill all?
Do everything possible to prevent selecting an unintended process for automated kill.
Use 'ps' options (user, group, etc.) to limit the selection first, relying on 'grep' only as absolutely necessary. Using 'grep
Also, once a process is identified for kill, store the process information and use it to verify that the PID still refers to what you want before issuing a kill. When killing groups of processes, parent/child relationships can cause several to die from one kill command, freeing the process table entry for the PID, which could then get grabbed by a new unrelated process. So the script should be smart enough to check that what it first selected is still what is active for the PID.
2 or more loops through the PIDs is a good idea, first doing soft kills, then any app-specific kills, finally the -9 option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 07:52 PM
08-28-2002 07:52 PM
Re: Kill all?
I had tried your script but it is not able to capture users in the primary as the /etc/group only shows the secondary group with userids. How should I check for the primary group users? As I had 2 group ids of 100 and 1000 and when I did a grep 100 on /etc/passwd it captures all the users in the group 100 and 1000 which is not what I want. Any advise? Thanks.