Filter cmd output with VBS and return value

Asked

Viewed 202 times

2

I have in my environment Arcserve Backup, which is the tape backup program we use, in it we have a program called ca_qmgr that manages the queues of backup Tvs, with a parameter via CMD so that it returns me the status of current Tvs as in the figure below :

inserir a descrição da imagem aqui

the script I used to return this output is as follows :

strCMD = ("""C:\Program Files (x86)\CA\ARCserve Backup\ca_qmgr.exe"" -list")

strResultado = CreateObject("WScript.Shell").Exec(strCMD).StdOut.ReadAll

wscript.echo strResultado

What I need now is the following, take the value of the field LAST-RESULT and if any of the Jobs is in the status "FAILED" return me the value numeric 1, and if all are ok return me the value numeric 0, I tried but could not anyone have any idea ?

1 answer

1

1) You could use his vbs but created by a bat

2) The same bat can call the execution of your vbs

3) On departure from the execution of vbs you filter strings by echoing 0 or 1


@echo off 

>"%temp%\Filtra_Saida.vbs"^
    (
    echo/ strCMD = ^("""C:\Program Files (x86)\CA\ARCserve Backup\ca_qmgr.exe"" -list"^)
    echo/ strResultado = CreateObject^("WScript.Shell"^).Exec^(strCMD^).StdOut.ReadAll
    echo/ wscript.echo strResultado
    )

set _CScript="%Windir%\System32\CScript.exe" //nologo & cmd /v/c set _Filtrar=!_CScript! "%temp%\Filtra_Saida.vbs"

:: Para listar um 0 ou um 1  apenas, e por execução use ::
%_Filtrar%|find "FALIED" >NUL && echo/1||echo/0

rem  ---------------------------------------------------- 

:: Para listar todas as ocorrências com 0 e 1 por linha, use linha abaixo ::  
for /f delims^=^ eol^= %%i in ('%_Filtrar%')do echo/%%i|find "FALIED" >nul && (echo/1)||(echo/0)

2>nul del /q /f "%temp%\Filtra_Saida.vbs"

Browser other questions tagged

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