-
Notifications
You must be signed in to change notification settings - Fork 1
/
MemoryCheck.sh
executable file
·43 lines (31 loc) · 931 Bytes
/
MemoryCheck.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
#!/bin/bash -x
if [ "$#" -ne 2 ]; then
echo "USAGE: $0 <EMAIL> <FREE MEMORY TRIGGER>"
exit 1
fi
subject="Low memory at $(hostname)"
email="$1"
freeMemTrigger="$2"
free=$(free -mt | grep Mem | awk '{print $4}')
if [[ "$free" -le $freeMemTrigger ]]; then
printf "From: Vladimir <vpopovic@tmns.com>\nTo: $email\nSubject: $subject\nMIME-Version: 1.0\nContent-Type: text/html\nContent-Disposition: inline\n
<html>
<head><title>$subject</title>
</head>
<body style=\"font: monospace;\">
<pre style=\"color: red\">Warning, server memory running low! Free memory: $free MB</pre>
<pre>
Checking the running listeners and free memory
With netstat -ltn we are checking running listeners:
$(netstat -ltn | grep 44)
Free memory is checked with free -mt command and bellow is current situation:
$(free -mt)
Current time: $(date '+%Y-%m-%d %H:%M:%S')
</pre>
</body>
</html>
" | sendmail -t
else
echo "OK"
fi
exit 0