After learning the shell script to get started, slowly try to write some scripts to practice practiced hand, in this first simple learning to write a system memory monitoring.
1, first of all to determine the need to take a look at the memory usage values, you can use the free command to operate
650) this.width=650; "border=" 0 "src="/e/u261/themes/default/images/spacer.gif "style=" border:1px solid RGB ( 221,221,221) Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat 50% 50%; "alt=" Spacer.gif "/> free-m Display
650) this.width=650; "alt=" Linux Ops shell script monitors memory-linux operations "src=" http://114share.com/uploads/allimg/160225/ 1-1602251i215632.png "style=" border:0px;width:400px;height:53px; "/>
Generally in monitoring memory is we are intercepting the third line (-/+ Buffers/cache) value. Once determined, you can use the pipe line and the grep command to get this value.
free-m | grep-| awk ' {print $4} '
Get to his value for 858
grep--It's a match for what you want to pick, and it's less familiar to learn about grep and awk commands.
2. Then decide whether this value is lower than the peak we want to judge and send an email alert. Such as: Peak is 900
Below write a simple script, here first not send the message just simple to judge him below the setting, output as a hint message.
Script content:
#!/bin/bash
nei=`free -m |grep -|awk ‘{print $4}‘`
[ $nei -lt 900 ]&&{
echo "你的内存使用已经小于峰值"
exit 0
}
A very simple script.
"Sehll learning" Linux operations a simple shell script monitors system memory