I am trying to create a logrotate script for a running nohup output ( without any line breakages - tried logrotate
package in system and observed several log lines are getting missed while rotating the continuously generating log file). Here's the steps i followed,
- Run the below script in background
#!/bin/bash log_split_pipe="/tmp/log_split_pipe" log_rename_interval_in_sec=60 log_file="/home/application/Logs/appname.log" semaphore="/home/application/Logs/appname.log.pause" write_log() { while read line do while [ -f $semaphore ] do sleep 1 done echo "$line" >> $log_file done < $log_split_pipe } write_log & log_start_time=$(date +%s) while true do tim_diff=$(expr $(date +%s) - $log_start_time) if [ $tim_diff -ge $log_rename_interval_in_sec ];then touch $semaphore mv /home/application/Logs/appname.log /home/application/Logs/appname-$(date +%Y'_'%m'_'%d'_'%H'_'%M).log rm -rf $semaphore log_start_time=$(date +%s) fi done
- mkfifo /tmp/log_split_pipe
- run application as
nohup ./application 2>&1 1 >/tmp/log_split_pipe &
Here the problem is, to the log file /home/application/Logs/appname.log
I am getting junk texts instead of the proper logs written by the process.
Can anyone help on the problem with the logic and to rectify?