SOLUTION
You can use the logrotate command along with the copytruncate option to rotate the log files in your environment. This option can also be combined with any other option pertaining to size-based or time-based rotation. For example, logrotate.conf:
/opt/weblogic/user_projects/domains/my_domain/servers/Server1/logs/er.out (or *.out) {
rotate 7 # rotates keeps logs for 7 weeks then overwrites.
size 200M # rotates log after the size reaches 200m
copytruncate # Copy logfile, then truncate it in place
missingok # tells logrotate not to issue an error if the log file is missing
notifempty # tells logrotate not to rotate a log if it's already empty
create 644 weblogic users # After rotation, re-create logfile with the specified permissions, owner, and group
endscript
}
The above script is simply an example of what parameters we can enter.
After creating the above script the following command can be used for log rotation.
logrotate -f logrotate.conf
Here -f is used for forced log rotation. For daily rotation we can setup something like a cron job. Following is an example of the same.
more /etc/cron.daily/logrotate
Default :
[root@mac2 bin]# more /etc/cron.daily/logrotate
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
You can consider something like the following for using a custom logrotate.conf:
$ cat /etc/cron.daily/logrotate
#!/bin/sh
/usr/sbin/logrotate /home/anjhawar/Oracle/Middleware/user_projects/domains/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
You can use the logrotate command along with the copytruncate option to rotate the log files in your environment. This option can also be combined with any other option pertaining to size-based or time-based rotation. For example, logrotate.conf:
/opt/weblogic/user_projects/domains/my_domain/servers/Server1/logs/er.out (or *.out) {
rotate 7 # rotates keeps logs for 7 weeks then overwrites.
size 200M # rotates log after the size reaches 200m
copytruncate # Copy logfile, then truncate it in place
missingok # tells logrotate not to issue an error if the log file is missing
notifempty # tells logrotate not to rotate a log if it's already empty
create 644 weblogic users # After rotation, re-create logfile with the specified permissions, owner, and group
endscript
}
The above script is simply an example of what parameters we can enter.
After creating the above script the following command can be used for log rotation.
logrotate -f logrotate.conf
Here -f is used for forced log rotation. For daily rotation we can setup something like a cron job. Following is an example of the same.
more /etc/cron.daily/logrotate
Default :
[root@mac2 bin]# more /etc/cron.daily/logrotate
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
You can consider something like the following for using a custom logrotate.conf:
$ cat /etc/cron.daily/logrotate
#!/bin/sh
/usr/sbin/logrotate /home/anjhawar/Oracle/Middleware/user_projects/domains/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0