View Single Post
Old 13th March 2006, 14:46
edge edge is online now
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,044
Thanks: 269
Thanked 154 Times in 133 Posts

Okay.. I got it :-)

The scrip will email me when cfmx7 is using more than 90% CPU pwr


# 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 will auto send an email.
# You will need to set a Cron job to run this script every xx minutes
# Set some needed things:
processToWatch="convert"        # in my case I need to watch convert
emailAddress="root@host"        # this is my main emailaddress
triggerValue=90                 # if the CPU use is above 90% send an email. DO NOT 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" ]
        set $LINE
        read LINE
        if [ $(echo "$3" | sed -e 's/\.[0-9]*//g') -gt $triggerValue ]; then
                mail -s "CPU message alert for: $processToWatch" $emailAddress <<-END
                This is to inform you that the following process: $processToWatch with PID (Process ID) $2 is now using more than your preset $triggerValue value.

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

Last edited by edge; 14th March 2006 at 00:37.
Reply With Quote