查看crontab服务状态: service crond status
为了方便我们可以把crontab设置成开机自启 在 /etc/rc.d/rc.local 脚本中加入 systemctl start crond.service
1.添加脚本 脚本内容:
#!/bin/bash used=`free -m | awk 'NR==2' | awk '{print $3}'` free=`free -m | awk 'NR==2' | awk '{print $4}'` echo "===========================" >> /var/log/mem.log date >> /var/log/mem.log echo "Memory usage | [Use:${used}MB][Free:${free}MB]" >> /var/log/mem.log if [ $free -le 100 ] ; then sync && echo 1 > /proc/sys/vm/drop_caches sync && echo 2 > /proc/sys/vm/drop_caches sync && echo 3 > /proc/sys/vm/drop_caches echo "OK" >> /var/log/mem.log else echo "Not required" >> /var/log/mem.log fi2.修改脚本权限:chmod +755
3.crontab -e进入
4.重启crontab,使配置生效 systemctl reload crond.service
5.crontab -l 确认