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

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
Office FileTransferAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Murugesan NagarajanShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NTCommented:
$ /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

Murugesan NagarajanShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NTCommented:
@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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.