Hpux pkill,a little help with script

This work

#!/usr/bin/sh

COMM=${1}
shift
UNIX95=1 ps -C ${COMM} -o pid='' | while read P
do
kill -15 ${P}
done

This don't work

#!/usr/bin/sh

COMM=${1}
shift
UNIX95=1 ps -C ${COMM} -o pid='' | while read P
do
kill -"$@" ${P}
done

I want to do pkill with signal(sighup,sikill or 2,9),how to pass arguments?
Thanks
Thanks

You could have the line:-

kill $1 ${P}

.... and then supply the full signal to call the script, e.g.

myscript -2

Does that do the trick?

Robin
Liverpool/Blackburn
Uk

Thanks
i will try it tomorrow

Interesting idea!
Here is an improved version that takes optional -signal parameter,
and also does some checks.

#!/bin/ksh -p
export PATH=/bin:/usr/bin:/usr/sbin:/sbin
set -f
prog=${0##*/}

usage(){
 echo "${1:+${prog}: $1}
usage: $prog [-signal] command ,..." >&2
 exit 1
}

case $1 in
-*)
 case $1 in
 -[A-Z][A-Z]*[A-Z]|-[1-9]|-[1-9][0-9]) signal=$1; shift;;
 *) usage "Bad signal";;
 esac
 ;;
esac
if [ $# -ne 1 ]; then
 usage "Bad number of arguments"
fi
comm=$1

UNIX95=1 ps -C "$comm" -o pid= | xargs -i kill $signal {}

pkill -signal 2 inetd
pkill: Bad number of arguments
usage: pkill [-signal] command ,..

Doesn't work

---------- Post updated at 11:09 AM ---------- Previous update was at 11:07 AM ----------

Honestly..not.
:slight_smile:

That didn't work because you don't need the word signal, just pkill -2 inetd

#!/usr/bin/env ksh
# should work with bash too
# usage: scriptname [-][signal-number|signal-name] pattern

if [[ $# > 1 ]]
then
    signal=$1
    shift;
else
    signal=-15
fi

if [[ $signal != -* ]]
then
    signal=-$signal
fi

echo pkill $signal "$1"    # remove the 'echo ' to actually run this

Might help. Test carefully!!

It's either

pkill -1 inetd

or

pkill -HUP inetd

the same syntax as with kill

kill -1 <pid_of_inetd>
kill -HUP <pid_of_inetd>

Run

kill -l

to list all the signals.

Don't work

#!/usr/bin/sh
COMM=${1}
shift
UNIX95=1 ps -C ${COMM} -o pid='' | while read P
do
kill $1 ${P}
done
[root@hpux src]# 
pkill -9  inetd

ps -ef|grep inetd
  root   938     1  0 18:35:25 ?         0:00 /usr/sbin/inetd