powerdomein
Verified User
- Joined
- Dec 28, 2005
- Messages
- 121
The following script works at Centos, Fedora:
Make a empty file and call it killlongproc.sh
Copy this:
--------------------
#!/bin/bash
# This script will kill process which running more than X hours
# egrep: the selected process; grep: hours
PIDS="`ps eaxo bsdtime,pid,comm | egrep "spamd|exim|mysqld|httpd" | grep " 1:" | awk '{print $2}'`"
# Kill the process
echo "Killing spamd, exim, mysqld and httpd processes running more than one hour..."
for i in ${PIDS}; do { echo "Killing $i"; kill -9 $i; }; done;
-----------------------
Stop this in your cronjob
15 * * * * * root /{directory}/./killongproc.sh
Have fun!
############## HISTORY ########################
I am trying to write a bash script that kills a (idle) process over 1 hour.
I am doing that because some script hinging up and uses memory.
Thanks a friend a write this one but i dont work.
Can some take a look an help to finish this script.
Also i want make it available in minutes to kill a running/idle process
--------------
#!/bin/bash
PROCS="spamd|exim|mysqld|httpd"
# Show all process which is running more than 00 hours for PROCESS. SO li
PIDS=$(ps eaxo etime,pid,comm | grep "$PROCS" | grep -v " 00:" | awk '{print $2}')
# Kill the process
echo "Killing $PROCS processes running more than one hour..."
kill -9 $PIDS
----------------------------
Make a empty file and call it killlongproc.sh
Copy this:
--------------------
#!/bin/bash
# This script will kill process which running more than X hours
# egrep: the selected process; grep: hours
PIDS="`ps eaxo bsdtime,pid,comm | egrep "spamd|exim|mysqld|httpd" | grep " 1:" | awk '{print $2}'`"
# Kill the process
echo "Killing spamd, exim, mysqld and httpd processes running more than one hour..."
for i in ${PIDS}; do { echo "Killing $i"; kill -9 $i; }; done;
-----------------------
Stop this in your cronjob
15 * * * * * root /{directory}/./killongproc.sh
Have fun!
############## HISTORY ########################
I am trying to write a bash script that kills a (idle) process over 1 hour.
I am doing that because some script hinging up and uses memory.
Thanks a friend a write this one but i dont work.
Can some take a look an help to finish this script.
Also i want make it available in minutes to kill a running/idle process
--------------
#!/bin/bash
PROCS="spamd|exim|mysqld|httpd"
# Show all process which is running more than 00 hours for PROCESS. SO li
PIDS=$(ps eaxo etime,pid,comm | grep "$PROCS" | grep -v " 00:" | awk '{print $2}')
# Kill the process
echo "Killing $PROCS processes running more than one hour..."
kill -9 $PIDS
----------------------------
Last edited: