#! /bin/shused=`free -m | awk 'NR==2' | awk '{print $3}'`free=`free -m | awk 'NR==2' | awk '{print $4}'`log_file=/tmp/mem.logecho "========================================" >> $log_filedate >> $log_fileecho "Memory usage before | [Use:${used}MB][Free:${free}MB]" >> $log_fileif [ $free -le 4000 ] ; then #sync && echo 1 |sudo tee -a /proc/sys/vm/drop_caches #sync && echo 2 |sudo tee -a /proc/sys/vm/drop_caches sync && echo 3 |sudo tee -a /proc/sys/vm/drop_caches used_ok=`free -m | awk 'NR==2' | awk '{print $3}'` free_ok=`free -m | awk 'NR==2' | awk '{print $4}'` echo "Memory usage after | [Use:${used_ok}MB][Free:${free_ok}MB]" >> $log_file echo "OK" >> $log_fileelse echo "Not required" >> $log_filefiexit 1
这个脚本将执行结果,记录到日志中。
能够知道时间! 能够对比,执行前,执行后的不同效果。 方便查看! 即便是通过Crontab 执行,也能查看日志。========================================2018年 07月 24日 星期二 10:22:08 CSTMemory usage before | [Use:6138MB][Free:514MB]Memory usage after | [Use:6137MB][Free:638MB]OK