Link to home
Start Free TrialLog in
Avatar of Baseball
Baseball

asked on

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.
Avatar of Baseball
Baseball

ASKER

Adjusted points to 150
Avatar of ozo
add your bin directory to $PATH
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
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.
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)



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.
How should an evaluation of what 'type' of kill be executed and in what order?
ASKER CERTIFIED SOLUTION
Avatar of djve
djve

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
bourne shell? alias? Hello, anybody home? wake up!
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 ?
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
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.
Add the ~/bin directory to your $PATH
NO: ~ does not stand for $HOME (it's just the same, sometimes)
NO: path=$PATH:~/bin  will not work in .cshrc or .login