一、需求
每晚11点59分切换日志,并生成日期后缀的日志
二、实施步骤
1、设置crontab 自动执行
[root@b32 jar_TongjiUdp_4.x]# crontab -l
## logrotate udplogs by days
59 23 * * * /usr/sbin/logrotate -f /opt/jar_TongjiUdp_4.x/rotateudplog -s /opt/jar_TongjiUdp_4.x/logrotate.status
2、rotateudplog文件内容
/opt/jar_TongjiUdp_4.x/logs/udplogs/*_log {
rotate 7
daily
copytruncate
missingok
dateext
dateformat .%Y-%m-%d.log
prerotate
/opt/jar_TongjiUdp_4.x/shutdown.sh
endscript
postrotate
/opt/jar_TongjiUdp_4.x/startup.sh
endscript
}
3、shutdown.sh 内容
#!/bin/sh
ps auxww | grep /opt/jar_TongjiUdp_4.x/udp_nvd.jar | grep -v grep | awk '{print $2}' | xargs -i kill -9 '{}'
exit 0
6、startup.sh 内容
#!/bin/sh
cd /opt/jar_TongjiUdp_4.x
nohup java -jar /opt/jar_TongjiUdp_4.x/udp_nvd.jar 40177 &
exit 0
三、必要条件
1、udp日志程序目录位置必须和上述配置和脚本相同
2、startup.sh和shutdown.sh必须要先手动执行通过
3、保证执行udp程序和执行crontab的用户是同一个
阅读(3162) | 评论(0) | 转发(0) |