Automatically kills shell scripts that consume more CPU resources _linux shell

Source: Internet
Author: User
Tags cpu usage

Copy Code code as follows:

#!/bin/bash

# march-13-2006
# Cpuuse Trigger script by Noel
#
# Bash code to watch a running program ' s CPU usage.
# if it ' s above a set value, it'll auto send an email.
# You'll need to set a Cron job to run this script every xx minutes
#
# Set Some needed things:
#
Processtowatch= "Convert" # in me case I need to watch convert
Emailaddress= "Root@host" # This are my main emailaddress
TRIGGERVALUE=90 # If the CPU is above 90% send an email. Don't use a DOT or comma!
TEMPFILENAME=TMP-CPU # Some name of the temp file for the PS, grep data

PS AUXWW | grep "$processToWatch" | grep-v grep >/tmp/$tempFileName
Export Line
(
Read Line
While [-N ' $LINE]
Todo
Set $LINE
Read Line
If [$ (echo "$" | sed-e ' s/\.[ 0-9]*//g ')-gt $triggerValue]; Then
Mail-s "CPU message alert for: $processToWatch" $emailAddress <<-end
This is to inform your following process: $processToWatch with PID (process ID) $ is now using the than your pre Set $triggerValue value.

Process: $processToWatch is using: $ of CPU power!
The command used is: $11
End
Fi
Done
) </tmp/$tempFileName

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.