我想在终端上写一行代码,以便在 cpu 负载较高时发送电子邮件。我有这个,但每次运行时都会发送
while true; do
lsof -u nagios | wc -l;
b=15;
a=$(uptime | awk '{print $10}' | cut -d ',' -f1);
uptime;
if echo $a $b | awk '{exit $1>$2?0:1}'; then
echo "DAL MCOM Nagios Load" | mailx -s "Load is greater than 15 $a" hai.le@xxx;
fi;
sleep 10;
done
我想在终端上执行此操作
答案1
假设负载为 3 或更高时您想要一封电子邮件:
max=3; load=$(cat /proc/loadavg | cut -d' ' -f1); [[ "${load%.*}" -ge "$max" ]] && mail -s "Load exceeded $max on $(hostname -s)" [email protected]