• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

Bourne Shell Script

I have created a Bourne shell Script in my 'bin' directory with the name of "Kill", but I need to know how to execute it from anywhere on the system in place of the 'kill'command (thus creating a "pseudo-command") that will process the pid(s) that I enter on the command line after the command (i.e. "kill 1234 1235) and will attempt to kill the processes through various kill levels with the -9 (kill attempt left for last since this is the most destructive.

Proper completion of this script will require an evaluation of what 'types' of kill should be executed and in what order.
0
Baseball
Asked:
Baseball
  • 3
  • 2
  • 2
  • +6
1 Solution
 
BaseballAuthor Commented:
Adjusted points to 150
0
 
ozoCommented:
add your bin directory to $PATH
0
 
alexhudghtonCommented:
put your bin directory in your PATH variable BEFORE the real bin directory. This will ensure that your bin is found first when searching for commands
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ozoCommented:
But the /usr/bin function is "kill", and the ~Baseball/bin function is "Kill".
It's usually safer to put your bin after the real bin, so that normal system functions don't change out from under you, and your scripts.
0
 
bedotCommented:
beware at modifying system commands: is dangerous to send a  kill -9 to some processes which need to clean their job before stopping;
 so for those, sending a kill -9 to them may left some unpretty files.

is not reasonable to give this possibility at all users.
is better to create another word to call your command (like uglykill, or crazykill), and place this new command in a directory accessible with the PATH variable;
in most system, there is a directory named /usr/local/bin or /usr/contrib/bin.

The PATH variable in a standard HPUX 10.20:
# echo $PATH
/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/contrib/bin:/opt/nettladm/bin:/opt/pd/bin:/usr/bin/X11:/usr/contrib/bin/X11:/opt/upgrade/bin:/opt/hparray/bin:/sbin:/home/root
#

BUT only users having a good knowledge of unix are able to use your command safely.

REMEMBER, however, that when a process in in a system call, you cannot kill it, the signal never pass thru the user mode: so, your process can treat only in user mode (if your program is blocked in system mode, you can never kill it, with none level, including 9)



0
 
BaseballAuthor Commented:
I am looking to create a Bourne Shell Script in my 'bin' directory that I had to name "Kill", and I have to be able to execute it from anywhere on the system in place of the kill command. It wiil process the pid(s) that I enter on the command line after the command (ie "Kill 1234 1235") and it will attempt to kill the processes through various kill levels with the -9 (kill) attempt left for last since it is the most destructive.

Also, an evaluation of what 'type' of kill should be executed and in what order.

Please someone help me, I am not good at UNIX at all, so, please be very through.
0
 
ozoCommented:
How should an evaluation of what 'type' of kill be executed and in what order?
0
 
djveCommented:
Use the alias command to override the default system binary:

alias kill=<path to your kill script>

however your script can't know if the last kill failed because the process is hung, defunct or just slow to die and release resources.

If your writing the script for users it won't hurt you but if you use your script as root you run the risk of corrupting your system.
0
 
thoellriCommented:
bourne shell? alias? Hello, anybody home? wake up!
0
 
alexhudghtonCommented:
I think you should put more effort into resolving the reasons why you are creating your script :-))

If you need a script of this nature, then you are probably going to be using it quite a lot - why ??

Do you have lots of processes that require killing? - what are they doing ? - why do you need to constantly kill them ?
0
 
ahoffmannCommented:
keep in mind that bash, csh, ksh, tcsh, zsh have a shell built-in kill command, so the PATH environment will not do the trick, usually
Simples method, ignoring all styleguides, etc. (see comments above), would be a alias
0
 
vvenksCommented:
Edit the PATH(or path) variable which would be specified in any of your .files(.login,.profile,.cshrc) as given below:
path=$PATH:~/bin
$PATH i hope you know is holding your path and ~stands for $HOME,so that you are now specifying a secondary path for all your command execution.
                                                                          Bye.
0
 
doug_levittCommented:
Add the ~/bin directory to your $PATH
0
 
ahoffmannCommented:
NO: ~ does not stand for $HOME (it's just the same, sometimes)
NO: path=$PATH:~/bin  will not work in .cshrc or .login
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 3
  • 2
  • 2
  • +6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now