Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stoping staring processes

Status
Not open for further replies.

GABRIEL123

Technical User
Jan 28, 2003
2
GB
I was wondering if you might be able to help. I have been asked to write a script in /bin/ksh which does the following :

1.) ask's the user what process they want to kill
2.) asks them to confirm if the process they have selected is the right one
3.) su to the userid which kills process
4.) kills process
4.) restarts process

any help would be apprecitaed as at the moment i am lost ??
 
1.Not ksh, this is bash/awk but should give you an idea.

2.This is not real easy since you have to worry about
some weird things, mostly options to the programs
that you are stopping for the restart.

The su I leave to you as well as the means of
stopping and restarting the programs with the
stored data obtained through getpData.


Code:
#!/bin/sh

function userIn() {
echo -n "Process to kill(?): "
read ans
        if [ ! -z "$ans" ] ; then 
           echo -n "You entered $ans, is this correct(y/n) :"
           read con
           if [ "$con" = "n" -o "$con" = "N" ] ; then 
              userIn
           fi
         fi
export ans
return 
}


function getpData() { 
name=$1
opt=$2
    ps -aux | awk -v id=$name -v cond=$opt ' {
                             if ($11 ~ id) {
                               if (cond == 1) {
                                   print $2
                               } else if (cond == 2) {
                                        for (x=11 ; x < NF ; x++) {
                                            line = line&quot; &quot;$x
                                        }
                                        print line
                                } 
                                line = &quot;&quot;
                              }
                      
                   }'                
 }


       
userIn
    if [ ! -z &quot;$ans&quot; ] ; then
       sigs=`getpData $ans 1`
       restartlist=`getpData $ans 2`
       #do_something_to_kill $sigs
       #do_something_to_restart $restartlist                          
    fi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top