1834162 Members
2444 Online
110064 Solutions
New Discussion

Scritp to Kill process

 
SOLVED
Go to solution
Alejandro Anguiano
Occasional Advisor

Scritp to Kill process

Hello all, I need a scritp to kill process with some accounts because I don't want they know the root password, maybe only run a script and they put the account and the script kill the process
Thanks
2 REPLIES 2
Bill Hassell
Honored Contributor

Re: Scritp to Kill process

A script to kill all processes owned by a specific user may be abit risky, especially if you kill processes that depend on each other or processes that will corrupt data files unless they are allowed to terminate correctly. The steps are fairly simple as far as a script to kill the processes. Use ps -u user_name to find all the processes and awk to extract the PID's (if any). Of course, never allow root as the user ID or a user ID = 0. (ps -u accepts either a name or an ID number). Also, your script will crash the system if your password file has duplicate root users (multiple users with UID=0). Note that this is never a good idea anyway.

The majority of the script must be devoted to not making a mistake. The script must check for a non-eistant user, it must check that the user does not have UID=0, and it should not allow 'system' UID's such as lp, www, ids, ftp and so on. Once you've validated the user ID, then loop through the PID's and kill them with kill -15. Don't start with kill -9 as it can corrupt data files. Processes that can't be terminated with kill -15 need examination for problems and poor coding.

Finally, the script should runnable only by root. Use chmod 700. Then download a copy of sudo and edit the sudoers file to allow only certain users to run the script.


Bill Hassell, sysadmin
Steven E. Protter
Exalted Contributor
Solution

Re: Scritp to Kill process

I am attaching a script, copied from a book that can kill a process or processes based on any input string. Its got safeguards for root processes but is still an extremely powerful and therefor dangerous script.

Use it carefully and at your own risk.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com