nohup執行的日誌日切解決版本

完美日切,內存中的日誌文件完全清空!!!找了很久才找到的日切版本,自己機器已驗證,項目環境還未驗證!!!
1、本人系統爲CentOS Linux release 7.6.1810

[root@yarcl ~]# /etc/redhat-release 
/etc/redhat-release:行1: 未預期的符號 `(' 附近有語法錯誤
/etc/redhat-release:行1: `CentOS Linux release 7.6.1810 (Core) '
[root@yarcl ~]#

PS:雖然顯示權限不夠,但是還是可以看出來是什麼系統的

2、nohup命令

nohup java .....省略一萬點內容.....
    --spring.profiles.active=${profiles} --isJar=true >> ${logPath}/${ModuleName}.log 2>&1 &

PS:
1)注意 --isJar=true後面採用的 >> 符號
2)執行命令最後面是2>&1 & 最後的&表示是後臺運行

3、定時任務調度

1 0 * * * sh /home/work/blog/blog-0.0.1/bin/split.sh > /home/work/blog/blog-0.0.1/logs/crontab-`date +"\%Y\%m\%d"`.log

4、split.sh腳本

#!/bin/bash
echo "start split log format!"

# Get today and last day
cur_date="`date +%Y-%m-%d`"
day_before="`date -d '-1 days' +%Y-%m-%d`"

# Enter logs path
binDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd ${binDir} && cd ../
curDir=`pwd`

# Rename the log file
cp ${curDir}/logs/blog.log ${curDir}/logs/blog-${day_before}.log
/bin/cp /dev/null ${curDir}/logs/blog.log

echo "end split log format!"
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章