- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Kill all processes PHN8 in group where user be...
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-01-2005 09:34 AM
08-01-2005 09:34 AM
ps- ef |grep PHN8 |awk '{print $2}' |xargs /usr/local/bin/sudo kill -9
This script will kill all processes with the name PHN8.
i would like to modify this script to search for user primary group and only kill
processes that particular user who run the script belong to.
Thanks for your help.
Regards,
Tom
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2005 09:58 AM
08-01-2005 09:58 AM
Re: Kill all processes PHN8 in group where user belongs to
ps -efg "group" | grep ...
and for the user part...
ps -efu "user" | grep...
also consider
ps -ef -C PHN8 -g "group" -u "user"
should limit you to a select group of users in a certain command group running PHN8 all in one command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2005 10:13 AM
08-01-2005 10:13 AM
Re: Kill all processes PHN8 in group where user belongs to
UNIX95= ps -fC PHN8
Now notice that this always finds processes that are exactly "PHN8", no more and no less. Then look at the -g and -u options to further limit the search.
Finally, do NOT use kill -9 as your kill signal. It will always cause problems. Use kill -15 to allow processes to terminate normally and cleanup correctly.
And don't be tempted to seet UNIX95 for everything as in: export UNIX95=. It will change other commands and libraries. Just use as shown above. NOTE: To see the hierarchy of processes (parent/chile), use the -H option with UNIX95=.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2005 12:56 PM
08-01-2005 12:56 PM
Re: Kill all processes PHN8 in group where user belongs to
Thanks for your help.
there are 2 group: IT and PROD
how can i get the process with user belongs to IT group
Thanks,
Tom
#UNIX95= ps -fC PH8SRVN -g IT
ps: wrong session number IT
UID PID PPID C STIME TTY TIME CMD
chis 21571 21569 0 17:31:57 ? 00:00 /opt/cognos/ph843d/bin/PH8SRVN
regina 16961 16959 0 17:06:05 ? 00:00 /opt/cognos/ph843d/bin/PH8SRVN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2005 06:01 PM
08-01-2005 06:01 PM
Re: Kill all processes PHN8 in group where user belongs to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2005 08:05 PM
08-01-2005 08:05 PM
Re: Kill all processes PHN8 in group where user belongs to
#UNIX95= ps -fC PH8SRVN -G IT
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2005 03:37 AM
08-02-2005 03:37 AM
Re: Kill all processes PHN8 in group where user belongs to
below are ids for users "alb" and "chis"
user alb gid=110(IT)
user chis gid=105(china
the commands below should return processes belong to group china ONLY but it returned both group china and IT.
Please how can i fix this.
Regards,
Tom
#UNIX95= ps -fC PH8SRVN -g china
#UNIX95= ps -fC PH8SRVN -G china
#id alb
uid=104(alb) gid=110(IT) groups=20(users),103(dba),105(china)
sunuxap1:[root]:/
#id chis
uid=163(chis) gid=105(china) groups=20(users),110(IT)
#UNIX95= ps -fC PH8SRVN -g china
ps: wrong session number china
UID PID PPID C STIME TTY TIME CMD
chis 23045 23043 0 07:48:53 ? 00:00 /opt/cognos/ph843d/bin/PH8SRVN
albany 23433 23431 0 07:51:09 ? 00:00 /opt/cognos/ph843d/bin/PH8SRVN
#UNIX95= ps -fC PH8SRVN -G china
UID PID PPID C STIME TTY TIME CMD
albany 29214 29212 0 08:25:16 ? 00:00 /opt/cognos/ph843d/bin/PH8SRVN
chis 29132 29130 0 08:24:51 ? 00:00 /opt/cognos/ph843d/bin/PH8SRVN
chis 29130 1593 0 08:24:51 ? 00:00 sh -c /opt/cognos/ph843d/bin/PH8INIT /opt/cognos/ph843d/bin/PH8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2005 06:28 AM
08-02-2005 06:28 AM
Re: Kill all processes PHN8 in group where user belongs to
So now your problem gets into lots of scripting...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2005 04:25 PM
08-03-2005 04:25 PM
SolutionIf more than one of the -C, -g, -G, -p, -R, -t, -u, -Z, and -U options
are specified, processes will be selected if they match any of the
options specified.
Why don't you try something like
$ UNIX95= ps -o user,group,pid,args -C PHN8 | awk '$2 == "china" {print $0}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2005 07:32 PM
08-03-2005 07:32 PM
Re: Kill all processes PHN8 in group where user belongs to
Thanks-Ermin
that is what i am looking for
it works very well
$ UNIX95= ps -o user,group,pid,args -C PHN8 | awk '$2 == "china" {print $0}'
One more question would like to ask:
if i want to replace group "china" with a variable as the line below. This line gives me the group name, when plug in together.
something is not correct.
id |cut -f2 -d" "|cut -f2 -d"("|cut -f1 -d")"
#!/usr/bin/sh
ID=/usr/bin/id
CUT=/usr/bin/cut
GPNAME=`$ID |$CUT -f2 -d" "|$CUT -f2 -d"("|$CUT -f1 -d")"`
UNIX95= ps -o user,group,pid,args -C PH8SRVN |awk '$2=="$GPNAME" {print $0}'
the $GPNAME of the last line did not pickup the variable return from the line above.
Can anyone please help?
Thank you very much,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2005 10:10 PM
08-03-2005 10:10 PM
Re: Kill all processes PHN8 in group where user belongs to
sh -x myscript
Or insert set -x as the second line in the script. However, your script can be simplified quite a bit:
#!/usr/bin/sh
export PATH=/usr/bin
GPNAME=$(id|awk '{print $2}'|tr -s "(" " "|cut -f2 -d=|awk '{print $1}')
UNIX95= ps -o user,group,pid,args -C PH8SRVN -G $GPNAME
The `cmds` construct is considered deprecated (see man sh-posix or man ksh) in favor of $(cmds). There are several other techniques to extract the group information from id. In this example, the group number is extracted rather than the name. For ps, the -G option accepts a GID number or symbolic name. And since ps can search for the GID, an additional string compare by awk isn't necessary.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2005 12:32 PM
08-04-2005 12:32 PM
Re: Kill all processes PHN8 in group where user belongs to
Change this
UNIX95= ps -o user,group,pid,args -C PH8SRVN |awk '$2=="$GPNAME" {print $0}'
to
UNIX95= ps -o user,group,pid,args -C PH8SRVN |awk -v GROUP=$GPNAME '$2==GROUP {print $0}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2005 11:57 PM
08-04-2005 11:57 PM
Re: Kill all processes PHN8 in group where user belongs to
It works great
Regards,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2005 11:59 PM
08-04-2005 11:59 PM
Re: Kill all processes PHN8 in group where user belongs to
Regards,
Tom