批处理if循环无法执行

时间:2016-06-01 10:52:57

标签: sql batch-file

我试图将if循环放在批处理脚本中但没有获得所需的结果,请查看代码ans建议if if错误在if循环  IF%禁止%== 1 echo" vvvvv"它没有正确比较 批处理脚本的1 == 1和1 == 0是否相同?

    call E:\utility\batfiles\DBAEnvProd.cmd
set dbname=UMRdb

set proc=UMRdb.[dbo].[maintenancemode] 
call %osqlExeLocation% -E -d%dbname% -S%svr% -w%w% -b -Q"exec %proc%" -o%pathout%%Maintmode.txt

@echo on
set "usrname=Y"
set "banfile=E:\utility\sysout\Maintmode.txt"
find /i "%usrname%" "%banfile%" >nul 2>&1&&set /a banned=1 || set /a banned=0
echo %banned%
echo comparing maintenance

IF  %banned% == 1  echo "vvvvv"
(

这里被禁止是1然后我不想执行它的其余代码 去结束 )

否则 应该执行普通代码

@echo on
REM ********************************************************************************
REM JOB: TCMP_DBA_M_MNT_UMR_ESSENTIAL
REM 
REM ********************************************************************************

set job=TCMP_DBA_M_MNT_UMR_ESSENTIAL
set RetCode=0
time /T & date /T

erase %pathout%%job%*.suc > nul
erase %patherr%%job%*.err > nul

REM ********************************************************************************
REM to display date and time
for /F "tokens=1-3 delims=:. " %%A in ('time/T') do set var=%%A%%B%%C%
set timestamp=%date:~4,2%%date:~7,2%%date:~10,4%
set timestamp1=%timestamp%%var%
REM
REM ********************************************************************************

:main

echo --- DB Growth Info
set proc=UMRdb.[dbo].[spCollectDBSpaceInfo] 
call %osqlExeLocation% -E -d%dbname% -S%svr% -w%w% -b -Q"exec %proc%" -o%pathout%%job%_spCollectDBSpaceInfo.txt
if errorlevel 1 (
    set RetCode=1
    goto endbad
)

echo --- Cleanup of output files older than 30 days in sysout folder 
call forfiles -p E:\utility\sysout /D -30 /M *.txt /C "cmd /c del @file" 






:ENDGOOD
set RetCode=0
ECHO SUCCESS!!! %svr% %job% %proc% 
echo %ErrMsg% > %pathout%%job%.SUC

GOTO END

:ENDBAD
set RetCode=1  
ECHO ERROR!!! %svr% %job% %proc% 
echo  SEE %pathout%%job%_%proc%.txt FOR ERRORS > %patherr%%job%.ERR

:END
time /T & date /T
echo %RetCode%

%pathexe%cc.exe %RetCode%

REM EXIT

1 个答案:

答案 0 :(得分:-2)

这是有问题的

IF  %banned% == 1  echo "vvvvv"

if ==执行字符串比较,我看到很多空格。 如果%banned%为1 ,则您将比较“1”==“1”。当您设置/禁止= 1时,最好进行数值比较

IF %banned% EQU 1  

或引用字符串比较

If "%banned%" == "1"