Link to home
Start Free TrialLog in
Avatar of Geert G
Geert GFlag for Belgium

asked on

adding choice of starting step

i have a windows cmd script which has calls to other scripts
it runs tasks in consecutive order and is called from several config scripts
echo.starting upgrade on %oracle_sid% at %dt% >%mlog%

echo  hit a key to start 
pause

rem step 1
call:eecho "preparing source"
call %sdir%\prepare_source_12102.cmd 

rem step 2
call:eecho "creating standby 12102"
call %sdir%\create_standby.cmd

rem step 3
call:eecho "rollforward standby"
set activate=NO
call %sdir%\activate_standby.cmd

echo hit a key to ACTIVATE STANDBY 
pause 

rem step 4
call:eecho "activate standby"
set activate=YES
call %sdir%\activate_standby.cmd

echo hit a key to start upgrade to 12.1
pause 

rem step 5
call:eecho "upgrade to 12.1.0.2"
call %sdir%\upgrade_db_12102.cmd

rem step 6
call:eecho "post upgrade on 12.1.0.2"
call %sdir%\post_upgrade_db_12102.cmd
call:eecho "end of post upgrade on 12.1.0.2"

echo hit a key to upgrade to 12.2
pause

rem  step 7
call:eecho "preparing source for 12.2.0.1"
call %sdir%\prepare_source_12201.cmd 

rem step 8
call:eecho "upgrade database to 12.2.0.1"
call %sdir%\upgrade_db_12201.cmd 

rem step 9
call:eecho "post upgrade database to 12.2.0.1"
call %sdir%\post_upgrade_db_12201.cmd 
call:eecho "end of post upgrade database to 12.2.0.1"

echo hit a key to switch sids
pause

rem step 10
call:eecho "rename sids %oracle_sid% to %dest_sid%"
call %sdir%\switch_sid.cmd %dest_home_2% %oracle_sid% %dest_sid%
call:eecho "end of switch sids to "%dest_sid%"

goto exit

:eecho
title %oracle_sid% %1 %2 %3 %4 %5 %6 %7 %8 %9
echo.%date% %time% %1 %2 %3 %4 %5 %6 %7 %8 %9 >>%mlog%
goto :eof


:exit
call:eecho "end of master upgrade script"
pause

Open in new window


problem is, a step can hang/fail and i need to be able to restart it from a certain step

anybody ideas on how to change this to allow to choose to start from a certain step
and how to display/maintain which steps have been done ?
Avatar of ZeropointNRG
ZeropointNRG
Flag of Australia image

You'd probably want to create a list to read from, and have your script auto delete each successful command. So if anything hangs, whatever line is there in your list, it will start from.

Line 1 <--successful, gets deleted and Line 2 moves to the top. When your script runs, call this .ini file or txt file each time.
Line 2
Line 3
Line 4
Line 5
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

>>allow to choose to start from a certain step
If you add error trapping and labels, you can use GOTO:
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/goto

>>and how to display/maintain which steps have been done
Create a log file with any appropriate name, possibly adding a date/time stamp to the file name and ECHO whatever you want to show where you are:
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/echo


All that said:  You probably have more options and flexibility if you switch to PowerShell.
Here is another approach.  The basic idea here is to establish a file that will hold the last step started in your script.  Then if you run it again it can look in that file to determine where to pick up again.  At the end you delete that file indicating the script ran to completion, and the next run will do a normal run, starting from step 1 again.

Here's the basic idea below, you might need to tweak it a little, but it could give you a starting point.

echo.starting upgrade on %oracle_sid% at %dt% >%mlog%

echo  hit a key to start 
pause

set restart_file=restart_step.txt
if exist "%restart_file%" (
    set restart_step=
    for /f "tokens=1" %%S in ('type "%restart_file%") do (
        if not defined restart_step (
            set restart_step=%%S
        )
    )
)
if "%restart_step%" NEQ "" goto STEP_%restart_step%

:STEP_1
rem step 1
echo 1 >"%restart_step%"
call:eecho "preparing source"
call %sdir%\prepare_source_12102.cmd 

:STEP_2
rem step 2
echo 2 >"%restart_step%"
call:eecho "creating standby 12102"
call %sdir%\create_standby.cmd

:STEP_3
rem step 3
echo 3 >"%restart_step%"
call:eecho "rollforward standby"
set activate=NO
call %sdir%\activate_standby.cmd

echo hit a key to ACTIVATE STANDBY 
pause 

:STEP_4
rem step 4
echo 4 >"%restart_step%"
call:eecho "activate standby"
set activate=YES
call %sdir%\activate_standby.cmd

echo hit a key to start upgrade to 12.1
pause 

:STEP_5
echo 5 >"%restart_step%"
rem step 5
call:eecho "upgrade to 12.1.0.2"
call %sdir%\upgrade_db_12102.cmd

:STEP_6
rem step 6
echo 6 >"%restart_step%"
call:eecho "post upgrade on 12.1.0.2"
call %sdir%\post_upgrade_db_12102.cmd
call:eecho "end of post upgrade on 12.1.0.2"

echo hit a key to upgrade to 12.2
pause

:STEP_7
rem  step 7
echo 7 >"%restart_step%"
call:eecho "preparing source for 12.2.0.1"
call %sdir%\prepare_source_12201.cmd 

:STEP_8
rem step 8
echo 8 >"%restart_step%"
call:eecho "upgrade database to 12.2.0.1"
call %sdir%\upgrade_db_12201.cmd 

:STEP_9
rem step 9
echo 9 >"%restart_step%"
call:eecho "post upgrade database to 12.2.0.1"
call %sdir%\post_upgrade_db_12201.cmd 
call:eecho "end of post upgrade database to 12.2.0.1"

echo hit a key to switch sids
pause

:STEP_10
rem step 10
echo 10 >"%restart_step%"
call:eecho "rename sids %oracle_sid% to %dest_sid%"
call %sdir%\switch_sid.cmd %dest_home_2% %oracle_sid% %dest_sid%
call:eecho "end of switch sids to "%dest_sid%"

if exist "%restart_step%" del "%restart_step%"
goto exit

:eecho
title %oracle_sid% %1 %2 %3 %4 %5 %6 %7 %8 %9
echo.%date% %time% %1 %2 %3 %4 %5 %6 %7 %8 %9 >>%mlog%
goto :eof


:exit
call:eecho "end of master upgrade script"
pause

Open in new window


»bp
Avatar of Geert G

ASKER

info in script, getting to that
anyway went back to the drawing board and i'm gonna using a config for my menu

stepname|title|script|action|nextstep
1.1|"preparing source"|prepare_source_12102.cmd|menu|1.2
1.2|"creating standby 12102"|create_standby.cmd|autonext|1.3
1.3|"rollforward standby"|"activate_standby.cmd NO"|menu|1.3
1.4|"rollforward standby"|"activate_standby.cmd YES"|menu|2.1
2.1|"upgrade to 12.1.0.2"|upgrade_db_12102.cmd|menu|2.2
2.2|"post upgrade on 12.1.0.2"|post_upgrade_db_12102.cmd|menu|3.1
3.1|"preparing source for 12.2.0.1"|prepare_source_12201.cmd|menu|3.2
3.2|"upgrade database to 12.2.0.1"|upgrade_db_12201.cmd|menu|3.3
3.3|"post upgrade database to 12.2.0.1"|post_upgrade_db_12201.cmd|menu|4.1
4.1|"rename sids %%oracle_sid%% to %%dest_sid%%"|"switch_sid.cmd %%dest_home_2%% %%oracle_sid%% %%dest_sid%%"|menu|5.1
5.1|"have a drink"|beer.cmd|menu|5.1

Open in new window


and then apply some of this logic:
https://www.dostips.com/DtTipsMenu.php

and use that %restart_step%  to remember what the last step was
using the persist variables of the advanced menu
@Geert G,

Are you all set with this now, or do you need more help?  If all set, could you please close it out now.  If you need help with the question close process take a look at:



»bp
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.