-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmonitor.sh
executable file
·46 lines (30 loc) · 1.3 KB
/
monitor.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
while true;do
disk=$(df --output=pcent / | tr -dc '0-9')
cpu=$(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}')
Cpu=${cpu%.*}
ram=$(free | grep Mem | awk '{print $3/$2 * 100.0}')
Ram=${ram%.*}
message_for_cpu="Current CPU Usage: $Cpu"
message_for_ram="Current RAM Usage: $Ram"
message_for_disk="Current DISK Usage: $disk"
if [ "$disk" -ge "10" ]; then
curl --url 'smtps://smtp.example.com:465' --ssl-reqd --mail-from '[email protected]' --mail-rcpt '[email protected]' --user '[email protected]:password' --upload-file - <<EOF
Subject: Disk Usage
Disk utilization is high please check. $message_for_disk
EOF
fi
if [ "$Cpu" -ge "80" ];then
curl --url 'smtps://smtp.example.com:465' --ssl-reqd --mail-from '[email protected]' --mail-rcpt '[email protected]' --user '[email protected]:password' --upload-file - <<EOF
Subject: CPU Usage
Disk utilization is high please check. $message_for_cpu
EOF
fi
if [ "$Ram" -ge "80" ];then
curl --url 'smtps://smtp.example.com:465' --ssl-reqd --mail-from '[email protected]' --mail-rcpt '[email protected]' --user '[email protected]:password' --upload-file - <<EOF
Subject: RAM Usage
Disk utilization is high please check. $message_for_ram
EOF
fi
sleep 60
done