#!/bin/sh

内存总量

total=$( free -m | grep Mem | awk '{print $2}')

已使用内存

used=$( free -m | grep Mem | awk '{print $3}')

空闲内存

free=$( free -m | grep Mem | awk '{print $4}')

内存使用率

rate=$((($total-$free)*100/$total))

time=$(date) echo '############$(date)###############'

#$1 is max Mem if [ $rate -gt $1 ] then echo 'rate=$rate freeMemory start!' sync sudo sh -c 'echo 3 >> /proc/sys/vm/drop_caches' echo 'FreeMemory Success!' else echo 'rate=$rate Memory is normal' fi

在第16行的时间获取命令中,应该加上 $ 符号,正确的写法是:

time=$(date)

sh 脚本报错:unary operator expected

原文地址: https://www.cveoy.top/t/topic/n5jy 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录