Batch if statement issue -


i trying figure out why batch script doesn't work properly. calling wmic see server model , deploy set of drivers specific model number.

the 'wmic csproduct name' outputs:

c:\>wmic csproduct name  name proliant dl360p gen8 

the command outputs:

c:\>for /f "tokens=3" %a in ('wmic csproduct name') ( echo %a) c:\>(echo gen8 ) gen8 

here script:

echo !time! - determining if hp gen 8 or 9 server... >> !logfile! wmic csproduct name | find /i "gen" >nul if %errorlevel% equ 1 ( set %errorlevel%=0 echo !time! - host doesnt appear hp gen 8 or 9 server...skipping install >> !logfile! echo !time! - exitcode !errorlevel! >> !logfile! if defined username (exit /b !errorlevel!) else exit !errorlevel! ) /f "tokens=3" %%a in ('wmic csproduct name') ( if %%a equ gen9 ( echo !time! - installing software , drivers hp gen 9>> !logfile! echo !time! - installing hp proliant gen9 chipset identifier windows (cp021663)>> !logfile! "%~dp0source\cp021663a.exe" /s /f /log=!msilogfile! echo !time! - installing headless server registry update windows (cp016819)>> !logfile! "%~dp0source\cp016819.exe" /s /f /log=!msilogfile! echo !time! - installing pfa server registry update windows (cp022305)>> !logfile! "%~dp0source\cp022305.exe" /s /f /log=!msilogfile! echo !time! - installing hp proliant integrated management log viewer windows server x64 editions (cp022717)>> !logfile! "%~dp0source\cp022717.exe" /s /f /log=!msilogfile! ) if %%a equ gen8 ( echo !time! - installing software , drivers hp gen 8>> !logfile! echo !time! - installing headless server registry update windows (cp016819)>> !logfile! "%~dp0source\cp016819.exe" /s /f /log=!msilogfile! echo !time! - installing pfa server registry update windows   (cp022305)>> !logfile! "%~dp0source\cp022305.exe" /s /f /log=!msilogfile! echo !time! - installing hp broadcom online firmware upgrade utility windows server x64 editions (cp024029)>> !logfile! "%~dp0source\cp024029.exe" /s /f /log=!msilogfile! ) else (echo !time! - ...model not listed, please add drivers >> !logfile!) 

the log file show following regardless if gen 8 or gen 9 server: *note missing ) @ end of 2nd line after cp016819. note not echoing first line "installing software , drivers gen 9"

logfile

14:06:21.16 - installing headless server registry update windows (cp016819 14:06:24.38 - installing pfa server registry update windows (cp022305) 14:06:27.47 - installing hp proliant integrated management log viewer windows server x64 editions (cp022717) 

so problem script goes through gen 9 if statement regardless if checks if gen 8 or 9. 2nd, skips first few lines of if statement (doesnt output log file can see above). know using gen 9 because gen 8 not have installer cp022717.

any appreciated.

thanks!

within block statement (a parenthesised series of statements) need escape close-parenthesis not closing block caret, : ^)

do every close-parenthesis have within echo statement, check balance of open , close-parentheses (indentation useful - leading spaces ignored) , ensure else programmed ) else (


Popular posts from this blog