用.sh脚本写了备份日志脚本 其实就是转移文件改名后重新建一个空文件

mv /alidata/log/nginx/access/wxtest.log /alidata/log/nginx/access/wxtest_log/wxtest_log_$(date +%Y%m%d-%H%M%S).log
touch /alidata/log/nginx/access/wxtest.log

 

但是这样的话 nginx不能立即认识这个新文件 需要服务器重新加载一下配置 或者杀掉子进程 由于杀子进程有风险 所以这里采用平滑重启nginx的方法 nginx -s reload

但是crontab -e 定时任务执行sh脚本的时候必须采用绝对路径的服务地址所以必须知道nginx服务的绝对路径

一般nginx的服务绝对路径地址是local那直接这样写就行 

/usr/local/nginx/sbin/nginx -s reload

 

但是由于不同服务器部署位置不一致 比如我们的测试服务器地址为 alidata/server/nginx-1.4.4/sbin/nginx

所以整体就这样写了sh脚本

mv /alidata/log/nginx/access/wxtest.log /alidata/log/nginx/access/wxtest_log/wxtest_log_$(date +%Y%m%d-%H%M%S).log
touch /alidata/log/nginx/access/wxtest.log
/alidata/server/nginx-1.4.4/sbin/nginx -s reload

而定时任务的crontab -e中这样写

0 2 * * * /alidata/log/nginx/back_log.sh ###每天2个小时将wxtest.log 重新建立并将日志按照时分秒挪到wxtest_log文件夹中 并平滑重启nginx

相关文章:

  • 2021-12-20
  • 2021-10-27
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2021-08-10
猜你喜欢
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2021-12-02
相关资源
相似解决方案