Cron job and shell script to kill a process if memory gets to high


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cron job and shell script to kill a process if memory gets to high
# 1  
Old 04-05-2012
Cron job and shell script to kill a process if memory gets to high

Hello,

I'd like to set a cron job that runs a shell script every 30 minutes or so to restart a java based service if the memory gets above 80%. Any advice on how to do this?

Thanks in advance!

- Ryan
# 2  
Old 04-05-2012
which OS ?
# 3  
Old 04-05-2012
Why not limit the amount of memory java can use instead?
# 4  
Old 04-05-2012
I fully agree with Corona688. It's what the unix ulimit command is for. Well written code should respect the limits. Bad code will crash. Try this on a test system.
# 5  
Old 04-05-2012
Wish I could, however, the application in question, Web Help Desk, is a memory hog.

---------- Post updated at 04:28 PM ---------- Previous update was at 04:28 PM ----------

I'm using CentOS 5.8
# 6  
Old 04-05-2012
try this

Code:
if [ `free -m | grep Mem | awk '$3/$2 > .8'`  != "" ];then
<restart your service>
fi

# 7  
Old 04-05-2012
Wow, this looks great. Thanks so much!

In the != "", can I assume that I enter !="java"? java is actually the name of the process that's taking up 80% or more of memory.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to monitor process with high CPU

Hi, Linux redhat 5.5 I need to write a kshell script that shows all the process that consume 100% CPU (or more. strange but there are time that top shows higger value that 100) and they are active more than 5 minute. The top command shows all the relevat information: The PID of the cpu ,... (0 Replies)
Discussion started by: yoavbe
0 Replies

2. Solaris

[DOUBT] Memory high in idle process on Solaris 10 (Memory Utilization > 90%)

Hi Experts, Our servers running Solaris 10 with SAP Application. The memory utilization always >90%, but the process on SAP is too less even nothing. Why memory utilization on solaris always looks high? I have statement about memory on solaris, is this true: Memory in solaris is used for... (4 Replies)
Discussion started by: edydsuranta
4 Replies

3. Shell Programming and Scripting

shell script to find a process by name and kill it

hi, Am a newbie to unix and wasnt able to write script to my requirement. I need a shell script, which should find a process by name and kill it. For eg: let the process name be "abc". I have different processes running by this name(abc), so should kill them all. Condition would be: if... (7 Replies)
Discussion started by: fop4658
7 Replies

4. Shell Programming and Scripting

shell script to kill process with respect to terminal

Hi, I've a script which kills all process, but i need a script shell script(sh), where it'll kill process on that particular terminal. below is example TY=`tty` for P in $TY do `kill -9 $P 2>/dev/null`; done echo "test process killed" break ... (3 Replies)
Discussion started by: asak
3 Replies

5. UNIX for Dummies Questions & Answers

cron job for the created shell script

Hi am newbie for unix shell.. how to create a cron job for my already created shell script.:confused: Thanks! (1 Reply)
Discussion started by: vidhyaS
1 Replies

6. Solaris

Shell Script gives error when run through cron job.

Hi, The following shell script runs without any problem when executed manulally. USED=$(df -h /arch | tail -1 | awk '{print $5}' | cut -d '%' -f 1) if then find /arch/AUBUAT/ -type f -mtime +0 | xargs rm find /arch/AUBMIG/ -type f -mtime +0 | xargs rm fi But the same gives below... (6 Replies)
Discussion started by: ksadiq79
6 Replies

7. Shell Programming and Scripting

Kill a process from parent shell within a shell script

Hi, I am looking for a solution for the following problem: Im Using tcpdump within a shellskript started in a subshell by using brackets: ( /usr/sbin/tcpdump -i ... -c 1 ) - I want the outout of tcpdump saved in a variable - Than tcpdump-Process in the Subshell should be killed - and I... (6 Replies)
Discussion started by: 2retti
6 Replies

8. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

9. Shell Programming and Scripting

Cron job shell script..

Hey Guys, i was trying out a shell script which has to remove a file for every 90 mins. this is the code i came up with . $ crontab -e file1 file1 contains 30 1 * * * * rm -r /folder1/folder2/somefile.txt Now i need the cron to run for every 90 mins. the problem with this is... (8 Replies)
Discussion started by: Irishboy24
8 Replies

10. Shell Programming and Scripting

Unix Script to find and kill a process with high memory utilization

Hi Unix Gurus i am somewhat new to unix scripting so need your help to create a script as below. # This script would find the process consuming memory beyond a certain #limit. if the meemory consumption is more than 100% for a period of 1 # minute for the specific process. the script would... (0 Replies)
Discussion started by: robinforlinux
0 Replies
Login or Register to Ask a Question