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