Recent Changes - Search:

Softwares

.

AdvancedServerLoadAlertScriptWithProcessStatus

Advanced Server Load Alert Script With Process Status.

  • Create a file with the script below
   vi   /root/loadalert

Get the process status report through e-mail for server load, you can try to add additional info to the code, to get more info through e-mail.

    #!/bin/bash
    #Wednesday, December 06 2006
    EMAIL="your email 1"
    EMAIL1="your email 2"
    SUBJECT="Alert $(hostname) load average is $L05"
    TEMPFILE="/tmp/$(hostname)"
    echo "Load average Crossed allowed limit." >> $TEMPFILE
    echo "Hostname: $(hostname)" >> $TEMPFILE
    echo "Local Date & Time : $(date)" >> $TEMPFILE
    echo "| Uptime status: |" >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    /usr/bin/uptime >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    echo "| Top 20 CPU consuming processes: |" >> $TEMPFILE
    ps aux | head -1 >> $TEMPFILE
    ps aux --no-headers | sort -rn +2 | head -20 >> $TEMPFILE
    echo "| Top 10 memory-consuming processes: |" >> $TEMPFILE
    ps aux --no-headers| sort -rn +3 | head >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    echo "| Memory and Swap status: |" >> $TEMPFILE
    /usr/bin/free -m >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    echo "| Active network connection: |" >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    /bin/netstat -tnup | grep ESTA >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    echo "| Disk Space information: |" >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    /bin/df -h >> $TEMPFILE
    echo "-----------------THE END-------------------" >> $TEMPFILE
    L05="$(uptime|awk '{print $(NF-2)}'|cut -d. -f1)"
    if test $L05 -gt 5
    then
    mail -s "$SUBJECT  $L05" "$EMAIL" < $TEMPFILE
    mail -s "$SUBJECT  $L05" "$EMAIL1" < $TEMPFILE
    fi
    rm -f $TEMPFILE
  • Now add Cron.
  * * * * * /root/loadalert >/dev/null 2>&1
Edit - History - Print - Recent Changes - Search
Page last modified on August 26, 2007, at 03:45 PM