Script to rotate .out file on every startup or size (.OUT file)

Office FileTransfer
Office FileTransfer used Ask the Experts™
on
Hi Experts,

I am looking for custom weblogic admin server startup script which can redirect output "directory_path/AdminServer.out" file. and rotate each time we execute the startup script so that older .out file moves to backup file.

example :

AdminServer.out
AdminServer.out0001
AdminServer.out0002
AdminServer.out0003
.....
AdminServer.out000X


Any help will be really appreciated.

Thank you
Neha
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT

Commented:
$ /bin/cat ./29121660_Neha.sh
#!/bin/bash
#/bin/rm /tmp/AdminServer.out00010002 /tmp/AdminServer.out0001 2>/dev/null
#/bin/rm /tmp/AdminServer.out00010002 2>/dev/null
WEBLOGIC_LOG_DIR=/tmp
cd $WEBLOGIC_LOG_DIR
/bin/ls -ltr $PWD/AdminServer.out* >/dev/null 2>&1
Ret=$?
if [ 0 -eq $Ret ]
then
        LAST_MODIFIED_FILE=$(/bin/ls -ltr $PWD/AdminServer.out* |\
        /usr/bin/tail -1 |\
        /usr/bin/awk '{
                printf( "%s", $NF);
        }')
        echo "$LAST_MODIFIED_FILE" | /bin/grep -E "\.out$" >/dev/null
        Ret=$?
        if [ 0 -eq $Ret ]
        then
                indx=0001
        else
                indx=$(echo "$LAST_MODIFIED_FILE" | /usr/bin/awk '{ printf("%04d", substr( $NF,index($NF,".out")+4)+1);}')
        fi
        while [ 1 ]
        do
                if [ ! -f "/tmp/AdminServer.out$indx" ]
                then
                        break
                fi
                indx=$(echo $indx | /usr/bin/awk '{ printf("%04d", substr( $NF,index($NF,".out")+4)+1);}')
        done
        echo "/bin/cp -ip $LAST_MODIFIED_FILE /tmp/AdminServer.out$indx"
        /bin/cp -ip $LAST_MODIFIED_FILE "/tmp/AdminServer.out$indx"
        Ret=$?
        if [ 0 -ne $Ret ]
        then
                echo "/usr/bin/touch /tmp/AdminServer.out$indx"
                /usr/bin/touch "/tmp/AdminServer.out$indx"
        fi
        #If you wish to clear old file you can remove comment at following lines:
        #if [ 0 -eq $Ret ]
        #then
        #       echo "echo -n >$PWD/AdminServer.out"
        #       echo -n >$PWD/AdminServer.out
        #fi
fi

Open in new window

Test result:
$ echo testing > /tmp/AdminServer.out
$ /bin/chmod u+x ./29121660_Neha.sh
$ /bin/ls -ltr /tmp/
total 1
-rw-r--r-- 1 murugesandins TES 8 Nov 13 14:58 AdminServer.out
$ ./29121660_Neha.sh
$ ./29121660_Neha.sh
/bin/cp -ip /tmp/AdminServer.out /tmp/AdminServer.out0001
$ /bin/cat /tmp/AdminServer.out0001
testing
$ /bin/cat /tmp/AdminServer.out
testing
$

Open in new window

murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT

Commented:
@Office FileTransfer
If resolved make the query resolved.
else provide related comment if any update required.
else close/withdraw this query using related approved comment.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial