Operating System - HP-UX
1752800 Members
5461 Online
108789 Solutions
New Discussion юеВ

Help with C Shell Script - Automatically Kill process

 
Laurie_2
Advisor

Help with C Shell Script - Automatically Kill process

Hi All,

I need some help writing a script. I need
to find all processes with the words voucher
and then find all those user and send them
a wall message (to just those users)" to log out in 2 minutes" and then
wait 2 minutes and then kill all those tasks as super user.

I need to kill the ppid and pid's. I do not want to kill pid 1, and sometime these processes attach to pid 1.

I then want to put this on the menu for my accountant to execute whenever she wants (password protected of course).

Thanks,
Laurie
How can you make the world a better place
4 REPLIES 4
Michael Steele_2
Honored Contributor

Re: Help with C Shell Script - Automatically Kill process

From the command line you can do this.

# ps -ef | while read a b c d e f
> do
> echo kill $b
> done

This is the 'preview' version. When ready remove the 'echo'.

> kill $b
Support Fatherhood - Stop Family Law
Rodney Hills
Honored Contributor

Re: Help with C Shell Script - Automatically Kill process

Here is a script I use prior to getting the backup process (I split my mirrored disks so I only need a 5 minute window of no users).

I first kill -15 to give the application a chance to recover itself, then I do a kill -9 for those that didn't die nicely. I also take the oppurtunity to delete any run away -ksh sessions.

I send the output of this script to a text file which I can review if need be.

HTH

-- Rod Hills

#!/usr/bin/ksh
# -- kick off production users prior to backup
echo "\07Production AVANTE backup process starts in 2 minutes\07" | /usr/sbin/wall
echo "System will be unavailable from 9:05 to 10:00 tonight" | /usr/sbin/wall
sleep 60
echo "\07Production AVANTE coming down in 60 seconds...\07" | /usr/sbin/wall
sleep 30
echo "\07Production AVANTE coming down in 30 seconds...\07" | /usr/sbin/wall
sleep 30
echo "\07Production AVANTE Halting !! Come back in 10 min\07" | /usr/sbin/wall
echo "Kill Soft Pass ..."
ps -ef | awk '$8=="UV"{print $0 ; system("kill -15 " $2)}'
sleep 30
echo "Kill Hard Pass ..."
ps -ef | awk '$8=="UV"{print $0 ; system("kill -9 " $2)}'
sleep 15
echo "Kill run away ksh Pass ..."
ps -ef | awk '$8=="-ksh" && $3=="1"{print $0 ; system("kill -9 " $2)}'
sleep 15
echo "Kill Proof ..."
ps -ef | awk '$8=="UV"{print $0}'
There be dragons...
Rodney Hills
Honored Contributor

Re: Help with C Shell Script - Automatically Kill process

Here is a script I use prior to getting the backup process (I split my mirrored disks so I only need a 5 minute window of no users).

I first kill -15 to give the application a chance to recover itself, then I do a kill -9 for those that didn't die nicely. I also take the oppurtunity to delete any run away -ksh sessions.

I send the output of this script to a text file which I can review if need be.

HTH

-- Rod Hills

#!/usr/bin/ksh
# -- kick off production users prior to backup
echo "\07Production AVANTE backup process starts in 2 minutes\07" | /usr/sbin/wall
echo "System will be unavailable from 9:05 to 10:00 tonight" | /usr/sbin/wall
sleep 60
echo "\07Production AVANTE coming down in 60 seconds...\07" | /usr/sbin/wall
sleep 30
echo "\07Production AVANTE coming down in 30 seconds...\07" | /usr/sbin/wall
sleep 30
echo "\07Production AVANTE Halting !! Come back in 10 min\07" | /usr/sbin/wall
echo "Kill Soft Pass ..."
ps -ef | awk '$8=="UV"{print $0 ; system("kill -15 " $2)}'
sleep 30
echo "Kill Hard Pass ..."
ps -ef | awk '$8=="UV"{print $0 ; system("kill -9 " $2)}'
sleep 15
echo "Kill run away ksh Pass ..."
ps -ef | awk '$8=="-ksh" && $3=="1"{print $0 ; system("kill -9 " $2)}'
sleep 15
echo "Kill Proof ..."
ps -ef | awk '$8=="UV"{print $0}'
There be dragons...
Francisco J. Soler
Honored Contributor

Re: Help with C Shell Script - Automatically Kill process

Hi, Laurie

1.- The wall command up to HP-UX 10.20 is for groups not users, so the first think you must do is to create a group for each user, so each group has only one user. (see man wall)

2.- Create 2 scripts, you can put them in /usr/local/bin or something similar. The first one is only one line that calls the other one.
first script:
su -c /usr/local/bin/2nd_script

This way the root password will be demanded to execute the second script.

I attach you this 2nd script.

Be careful to put the chmod 755 to the scripts to make it executables.

Edit the script and make the correct changes, mainly in the user groups initialization and the message sent to the users.

3.- To put in the screen menu you must edit the file in home users ~/.dt/dtwmrc and add an entry in the Root Menu.

Frank.
Linux?. Yes, of course.