Operating System - HP-UX
1837404 Members
3011 Online
110116 Solutions
New Discussion

Script to kill an user proccess

 
GNOM
Frequent Advisor

Script to kill an user proccess

Hi,
I need help to make a shell script to kill automatically all process of a given user.
So I'll give the user $LOGNAME and the scrip should kill all proccess of this user.

Thanks for your help
5 REPLIES 5
Pete Randall
Outstanding Contributor

Re: Script to kill an user proccess

See the attached "resetuser" script.


Pete

Pete
RikTytgat
Honored Contributor

Re: Script to kill an user proccess

Or in short:

kill - $(ps -fu|awk '{print $2}')

Regards,
Rik
GNOM
Frequent Advisor

Re: Script to kill an user proccess

Thanks,

How can I set the UID to root
so that no root users be able to execute the script.
bye

Alex Lavrov.
Honored Contributor

Re: Script to kill an user proccess

Use sudo, it allows to run scripts as other users and you jave a full control over it.

http://www.sudo.ws/

And here is a version compiled for HPUX:
http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/sudo-1.6.8p7/
I don't give a damn for a man that can only spell a word one way. (M. Twain)
rveri
Super Advisor

Re: Script to kill an user proccess

Hi Amignom ,

Simply use this command it will kill the users session:

1. If sudo permission has been set to your user , or use as a root user.


#PROC=`ps -fu username | grep -v PID | awk '{print $2}'` ; kill -9 `echo $PROC`
-----------------------------------------


username= The username whose proceses you want to kill.

Cheers ,

Veri.