Standard out file is very important log file in Weblogic
domain for each of the Weblogic Server instance which gets generated from Node
Manager Process. However, Weblogic des not provide any out of box facility to
rotate this log file.
Often in many implementation administrator ended up writing
a custom shell script to rotate this file on certain interval using cron job or
using OS based log rotation utility such
has ‘logrotate’.
SOA Administrator normally does not prefer to use the OS log
rotation utility because they normally do not have root user access which
required to make configuration changes for ‘logrotate’ utility, instead they
prefer to write a custom shell script which can be handle using ‘oracle’ user,
so that they can have full control over script customization.
Inside that custom script very basic logic been used as
below -
1)
Create a dummy file with actual WLS instance
name with timestamp e.g. Output_File=WLS_OSB1.{Time_Stamp}
2)
Copy the content of original file WLS_OSB1 to
dummy file e.g. cp WLS_OSB1 ${Output_File}
3)
Clear the content of current WLS_OSB1.out file
e.g. cp /dev/null ${Log_File} or cat /dev/null ${Log_File} or > ${Log_File} or truncate
${Log_File} --size 0 etc.
4)
Tar the old log file e.g. tar -cvf ${Output_File}.tar ${Output_File}
5)
Move that old file to some archive location e.g.
mv ${Final_Zip_File} ${Archieve_Path}
Although, above steps helps to control the growing size of
.out file but it also introduce a problem as describe below which is objective
of this post.
Once WLS server instance file get rotated and WLS server
tries to write first line in newly rotated file, it intermittently insert the
junk character in first line, which make .out file unstable. Whenever we tries
to open that file in any editor such as notepad++ or textpad etc, editor hangs because
of junk character inside it. Even, if we tries to open the file using vi editor
putty session get hangs.
Below snap show the file content when we tries to open from
Notepad++
Notepad Editor View WLS_OSB1.out
VI Editor view using Putty
WLS_OSB1.out
Solution:
To fix this problem we have to delete the first line for
existing WLS instance .out file which contains the junk character.
There could be many other possible ways to do it. However, I
found below two suitable command to do that-
1)
Using sed command – sed '1d'
WLS_OSB1.out > WLS_OSB1.out
2)
Using trail command – echo
"$(tail -n +2 WLS_OSB2.out)" > WLS_OSB1.out
Using both command I was able to remove the junk character
what has been highlighted in above snaps. I also tried using various regular
pattern in sed command but nothing worked for me. Also tried ‘dos2unix’ command
it didn’t help.
The environment where I had implemented this solution having
two custom shell scripts now. The first script run in midnight at 12 am exactly
to rotate the .out file for entire domain and another shell script which runs
after 15 minute and remove the junk character from the current .out file.
I hope this article will helps to manage .out file
efficiently and keep track of all old .out files up to certain no. of days as
per your company business requirement.
No comments:
Post a Comment