Hpux pkill,a little help with script


 
Thread Tools Search this Thread
Operating Systems HP-UX Hpux pkill,a little help with script
# 1  
Old 05-24-2013
Hpux pkill,a little help with script

This work
Code:
#!/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
Code:
#!/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
# 2  
Old 05-24-2013
You could have the line:-
Code:
kill $1 ${P}

.... and then supply the full signal to call the script, e.g.
Code:
myscript -2


Does that do the trick?


Robin
Liverpool/Blackburn
Uk
# 3  
Old 05-24-2013
Thanks
i will try it tomorrow
# 4  
Old 05-24-2013
Interesting idea!
Here is an improved version that takes optional -signal parameter,
and also does some checks.
Code:
#!/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 {}

# 5  
Old 05-27-2013
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 ----------

Quote:
Originally Posted by rbatte1
You could have the line:-
Code:
kill $1 ${P}

.... and then supply the full signal to call the script, e.g.
Code:
myscript -2

Does that do the trick?


Robin
Liverpool/Blackburn
Uk
Honestly..not.
Smilie
# 6  
Old 05-27-2013
Quote:
Originally Posted by Linusolaradm1
pkill -signal 2 inetd
pkill: Bad number of arguments
usage: pkill [-signal] command ,..

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

Code:
#!/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!!
# 7  
Old 05-28-2013
It's either
Code:
pkill -1 inetd

or
Code:
pkill -HUP inetd

the same syntax as with kill
Code:
kill -1 <pid_of_inetd>
kill -HUP <pid_of_inetd>

Run
Code:
kill -l

to list all the signals.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Hpux and bacula script

# bacula status /opt/bacula/bin/bacula-ctl-fd: UNIX95=1;: not found bacula-fd is stopped #! /bin/sh # # bacula-ctl-fd This shell script takes care of starting and stopping # the bacula File daemon. # # This is pretty much watered down version of the RedHat script # that... (9 Replies)
Discussion started by: Linusolaradm1
9 Replies

2. UNIX and Linux Applications

Unix pkill error; does wily obstruct me killing the process?

have two scripts on Unix; one that starts some processes and the other one for killing a process. At first, I ran the .sh without WILY in it and it worked perfectly; in this way, I could also ran my stopper process. However I need WILY in this so I added it to my script but this time, a message... (1 Reply)
Discussion started by: nerdogan551
1 Replies

3. UNIX for Advanced & Expert Users

pkill won't work on firefox anymore

Can someone tell me why pkill won't work on firefox anymore? (11 Replies)
Discussion started by: cokedude
11 Replies

4. Shell Programming and Scripting

Pkill Argument issue

Hi All, I am writing a shell script to kill user processes on all servers using pkill. But when i am passing user id directly ist works but when password userid as variable its not working & getting the below error. # ssh hpadmin@vmtest15.zin33 'sudo /usr/bin/pkill -u $unixid'... (2 Replies)
Discussion started by: ajaincv
2 Replies

5. HP-UX

pwage-hpux-T for Trusted HPUX servers

I'm sharing this in case anybody needs it. Modified from the original solaris pwage script. This modified hpux script will check /etc/password file on hpux trusted systems search /tcb and grep the required u_succhg field. Calculate days to expiry and notify users via email. original solaris... (2 Replies)
Discussion started by: sparcguy
2 Replies

6. Shell Programming and Scripting

Suppressing the terminated message from pkill & killall commands in a bash script

Hi all, I've been pulling my hair out with this problem for 3 days:wall: now without success any help would be massively appreciated. Basically the script is used to shutdown a rails server so a new IP address can be assigned, the shutdown part is taken care of in function_one using the... (2 Replies)
Discussion started by: danmc
2 Replies

7. Linux

Script migration help from HPUX

Hi, We are looking for the extensive list of Commands/Syntax that were working in HP-UX and will not work on LINUX. We would find such commands and modify them accordingly. Do we have any reference sites or documents. You help would be greatly appreciated. Thanks in advance (2 Replies)
Discussion started by: vijaipersonal
2 Replies

8. UNIX for Dummies Questions & Answers

kill/pkill process by CMD info.

I have a process that I'd like to kill. Doing a "ps -fu myusername" gives me: UID PID PPID C STIME TTY TIME CMD myusername 5443 1 0 10:05 ? 00:00:00 /bin/sh /some/path/crap.sh -s /yet/another/path/parentProcess myusername 5593 5443 0 ... (2 Replies)
Discussion started by: mrwatkin
2 Replies

9. Shell Programming and Scripting

Need Script to Use CPUs on a HPUX server to simulate Workload Manager on HPUX.

I am running HPUX and using WLM (workload manager). I want to write a script to fork CPUs to basically take CPUs from other servers to show that the communication is working and CPU licensing is working. Basically, I want to build a script that will use up CPU on a server. Any ideas? (2 Replies)
Discussion started by: cpolikowsky
2 Replies

10. Solaris

Diffirence between Kill and Pkill Command???

Diffirence between Kill and Pkill Command??? (1 Reply)
Discussion started by: udayn
1 Replies
Login or Register to Ask a Question