linux定时任务清除缓存+开机启动脚本

定时任务

编写.sh清除文件

#!/bin/bash   
--shell环境变量

echo 3 > /proc/sys/vm/drop_caches
--清理所有内存 缓存 (1.2 部分清除 3 所有清除 0 不清除)

开启定时任务)(centos)

vim /etc/crontab
0  */4  *  *  *  root nohup sh /home/j脚本名称.sh &
--每4小时执行一次

开机启动

编写sh文件

#!/bin/bash 

/usr/local/nginx/sbin/nginx   
/etc/init.d/fdfs_trackerd restart
/etc/init.d/fdfs_storaged restart
systemctl restart redis
nohup java -jar /home/face/attendance-admin.jar > /home/face/nohup.out &
  • 将sh文件赋予可执行权限(chmod +x 文件名.sh 例如:sh的文件路径 /home/java/文件名.sh )
  • 将sh文件添加到开机启动中
vim /etc/rc.d/rc.local


#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/home/java/文件名.sh 
  • 将rc.local 文件赋予可执行权限(chmod +x rc.local)
    完成

你可能感兴趣的:(linux定时任务清除缓存+开机启动脚本)