Loading... >  > 使用nohup 命令进行进程不中断启动,会产生nohup.out 文件,并且文件会不断增大。我们使用定时器每天将日志文件进行分割处理。 * 编写 `log.sh` shell 脚本 ```bash #!/bin/bash thedate=$(date --rfc-3339=date) predate=$(date +%Y-%m-%d --date="-7 day") rmfile="/root/codes/data/server/log/${predate}.out" outfile="/root/codes/data/server/log/logs.out" if [ -f ${rmfile} ]; then rm -f ${rmfile} fi if [ -f ${outfile} ]; then cp ${outfile} /root/codes/data/server/log/${thedate}.out echo "" >${outfile} fi exit 0 ``` - 授权 ``` chmod u+x log.sh ``` * 加入定时器 ```bash # 定时器 crontab -e # cron 表达式 0 01 * * * /root/codes/data/server/log/log.sh ``` 或 - 编辑 vi /etc/crontab ```bash SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed 0 0 * * * root /root/codes/data/server/log/log.sh #每天凌晨执行脚本 ``` - 重启服务打完收工 ```java service crond restart ``` 最后修改:2022 年 08 月 27 日 © 允许规范转载 打赏 赞赏作者 微信 赞 1 如果觉得我的文章对你有用,请随意赞赏