#!/bin/bash
SUBJECT="WARNING CPU USAGE HIGH"
[email protected]
MESSAGE=/tmp/messages
echo "#######################" > $MESSAGE
echo "CPU statistics as follows.." >> $MESSAGE
mpstat >> $MESSAGE
echo "#######################" >> $MESSAGE
CPU_USAGE=$(top -b -n1 | awk '/^%Cpu/ {print }' | cut -d. -f1)
[ "$CPU_USAGE" -gt 1 ] && mail -s "$SUBJECT" "$TO" < $MESSAGE
O script acima envia um email quando o uso da CPU é maior que o limite. Embora eu tenha prescrito um vaild gmail id no código, ele ainda está enviando o e-mail para /var/mail/root
. Como consertar isto?
Eu fiz a alteração necessária seguindo o link abaixo. Mas o /var/mail/root
está aparecendo
Return-Path: <root@server2-SandyBridge-Platform>
Received: by server2-SandyBridge-Platform (Postfix, from userid 0)
id A4977138269C; Fri, 14 Oct 2016 10:53:11 +0530 (IST)
Subject: WARNING CPU USAGE HIGH
To: <[email protected]>
X-Mailer: mail (GNU Mailutils 2.99.98)
Message-Id: <20161014052311.A4977138269C@server2-SandyBridge-Platform>
Date: Fri, 14 Oct 2016 10:53:11 +0530 (IST)
From: root@server2-SandyBridge-Platform (root)
#######################
CPU statistics as follows..
Linux 3.13.0-98-generic (server2-SandyBridge-Platform) Friday 14 October 2016 _x86_64_ (4 CPU)
10:53:11 IST CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
10:53:11 IST all 3.07 0.15 1.13 1.48 0.00 0.01 0.00 0.00 0.00 94.17
#######################'
There is no mail in my mail id though.@Terrance