Repeat loops with conditions seem not to work

Asked

Viewed 286 times

1

Obs.: I believe it is error in the variables, because the loops do not work.

This code stores the average execution time of backups SQL of the month and uses this time to limit the execution time of backup. If time is greater than the average * 2 + 60 he has to give Kill in the CMD process to close other batch files that have been scheduled and may be running or crashing.

I did it through an accountant at if, but the conditionals aren’t working.

echo MONITOR DE ERRO BKUP SQL

@echo on

:: get date
for /F "tokens=1-3 delims=/ " %%i in ('date /t') do (

    set dd=%%i
    set mm=%%j
    set yy=%%k
)


if exist "%temp%\sqldump_elapsed_time%yy%%mm%.txt" (

    set /p sqldump_elapsed_time=<"%temp%\sqldump_elapsed_time%yy%%mm%.txt"

    set /a "tempolimite = (sqldump_elapsed_time * 2) + 60"

    set /a "count = 0"

    pause

:DELAYFUNCTION
    if count LEQ tempolimite (

        if not exist "%temp%\sqldump_bkcup_confirm.txt" (
                TIMEOUT 1 /nobreak
            set /a "count = count + 1"
            echo %count%
            echo %tempolimite%
                goto :DELAYFUNCTION
        )

        if exist "%temp%\sqldump_bkcup_confirm.txt" (
            set /p verificador=<"%temp%\sqldump_bkcup_confirm.txt"
            if verificador=="ok" (
                echo Backup Confirmado - Fechar Programa
                pause
                exit /b
            )
        )
    )

)
>"%temp%\ver.txt" echo %verificador%
echo Backup ERRO - KILL no CMD
pause
REM ESCREVER FUNÇÃO TASKKILL CMD.EXE (PROCURAR COMO ESCREVE)

exit /b

1 answer

1

inserir a descrição da imagem aqui Try using expanded variables with the command setlocal enabledelayedexpansion

Also remove spaces before/after**=**when "set" the values for your variables

Detail of date, output from WMIC Path Win32_LocalTime Get Day,Month,Year is standardized, which does not happen with the command date, where the user changes the date layout on the system.

@echo off & setlocal enabledelayedexpansion & cd /d "%~dp0"
cls & mode con cols=62 lines=5 && color 9F & title MONITOR BACKUP SQL ...

rem :|  Cria variavel para data adicionando 0 para dia/mes menores que 10... 
for /f "tokens=1-3 delims= " %%a in ('WMIC Path Win32_LocalTime Get Day^,Month^,Year^| findstr /r "[0-9]"') do (
     set "data=%%c" & if not %%b geq 10 (set "data=!data!0%%b") else (set "data=!data!%%b")
     if not %%a geq 10 (set "data=!data: =!0%%a") else (set "data=!data: =!%%a") 
   )

:_loop_:
echo/ & echo/Aguardando gerar arquivo: "sqldump_elapsed_time!data:~,6!.txt" & timeout -t 5 & cls
if exist "%temp%\sqldump_elapsed_time!data:~,6!.txt" (

     set /p sqldump_elapsed_time=<"%temp%\sqldump_elapsed_time!data:~,6!.txt"
     set /a "tempolimite= 60 + !sqldump_elapsed_time! * 2" & set "show_t_limit=000!tempolimite!"
     set "count=0" & mode con cols=48 lines=5 ) else ( goto :_loop_:)

     )

:DELAYFUNCTION
cls & echo/ & echo/     MONITOR DE ERRO BACKUP SQL :: !data! & echo/

if !count! leq !tempolimite! (

     if not exist "%temp%\sqldump_bkcup_confirm.txt" (

         set "show_t_count=000!count!" & set /a "count=!count! + 1" 
         echo/   Tempo limite: !show_t_limit:~-4! ^| Tempo decorido: !show_t_count:~-4!
         timeout /t 1 /nobreak >nul & goto :DELAYFUNCTION

       ) else (

         set /p verificador=<"%temp%\sqldump_bkcup_confirm.txt" 

         if /i "!verificador!" equ "ok" (

             >"%temp%\ver.txt" echo/!verificador! & goto :kill_cmd:

           ) else (

             color F4 & echo/ & echo/  ERRO: Verificador = "!verificador:~-25!"
             echo/  Backup nao Confirmado^^! - Fechar Programa... 
             echo/  Backup ERRO - KILL no CMD & goto :kill_cmd:

           )
       ) 
   )
   )

:kill_cmd:
timeout -t -1 & taskkill /f /im "CMD.EXE" /t & exit     

Browser other questions tagged

You are not signed in. Login or sign up in order to post.