If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Free Shell script kill Zombie Processes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-30-10, 12:26
sles sles is offline
Registered User
 
Join Date: Sep 2010
Posts: 3
Free Shell script kill Zombie Processes

Code:
#! /bin/bash
#
# Zombie processes killing script. Must be run under root.

case "$1" in
--admin)
        stat=`ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print"pid: "$3" *** parent_pid: "$4" *** status: "$10" *** process: "$13}' | grep ": Z"`

        if ((${#stat} > 0));then
            echo zombie processes found:
            echo .
            ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print"pid: "$3" *** parent_pid: "$4" *** status: "$10" *** process: "$13}' | grep ": Z"
            echo -n "Kill zombies? [y/n]: "
            read keyb
            if [ $keyb == 'y' ];then
                echo killing zombies..
                ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print$4" status:"$10}' | grep "status:Z" | awk '{print $1}' | xargs -n 1 kill -9
            fi
        else
            echo no zombies found!
        fi
;;
--cron)
        stat=`ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print"pid: "$3" *** parent_pid: "$4" *** status: "$10" *** process: "$13}' | grep ": Z"`
        if ((${#stat} > 0));then
        ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print$4" status:"$10}' | grep "status:Z" | awk '{print $1}' | xargs -n 1 kill -9
        echo `date`": killed some zombie processes!" >> /var/log/zombies.log
        fi
;;
*)      echo 'usage: kill-zombies {--cron|--admin}'
;;
esac
exit 0
----------------------------------------------------------------------
How to using

Thank you tips from suse.in.th
Reply With Quote
  #2 (permalink)  
Old 10-01-10, 02:11
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
while it's kind of sles to post this I'll just mention that you need to have your head examined if you like to copy code of the web and run it on your server. I don't have time to check the code out. I'd suggest you look at people's post counts to get a feeling of how much trust to have.
__________________
Mike
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On