2016-11-26 96 views
0

我想做一個批處理腳本,如果有無效的對象,它會自動檢查數據庫中的所有客戶 。與sqlplus批量連接

我遇到的問題是,當我試圖打印出結果.txt文件不像包含連接信息那樣可讀。

有什麼方法可以在文件中打印只有無效的信息而沒有任何其他信息? 在此先感謝

我的代碼如下:

@echo off 
setlocal EnableExtensions 

set "Server[1]=DB1" 
set "Server[2]=DB2" 
set "Server[3]=DB3" 

set "Message=" 
:Menu 
cls 
echo.%Message% 

set "x=0" 
:MenuLoop 
set /a "x+=1" 
if defined Server[%x%] (
    call echo %x%. %%Server[%x%]%% 
    goto MenuLoop 
) 
echo. 


:Prompt 
set "Input=" 
set /p "Input=Select the DATABASE which will be checked : " 

if not defined Input goto Prompt 
set "Input=%Input:"=%" 
set "Input=%Input:^=%" 
set "Input=%Input:<=%" 
set "Input=%Input:>=%" 
set "Input=%Input:&=%" 
set "Input=%Input:|=%" 
set "Input=%Input:(=%" 
set "Input=%Input:)=%" 
:: Equals are not allowed in variable names 
set "Input=%Input:^==%" 
call :Validate %Input% 

:: Process Input 
call :Process %Input% 
goto End 

:Validate 
set "Next=%2" 
if not defined Server[%1] (
    set "Message=Invalid Input: %1" 
    goto Menu 
) 
if defined Next shift & goto Validate 
goto :eof 

:Process 
set "Next=%2" 
call set "Server=%%Server[%1]%%" 

:: Run Checks 
:: Step 2. Match on the Server names and perform checks for each 
if "%Server%" EQU "DB1" echo checks for DB1 ... 
if "%Server%" EQU "DB2" echo checks for DB2 ... 
if "%Server%" EQU "DB3" echo checks for DB3 ... 

set hostname=%Server%.domain.gr:1528 
set password=pass 

echo Report > Report.txt 
echo. >> Report.txt 

for %%S in (
    customer1 
    customer2 
    customer3 
    customer4 
) do ( 
    echo Customer %% checked .... [OK] 
    echo Customer %%S >> Report.txt 
    exit|sqlplus SYS/"%password%"@%hostname%/%%S as SYSDBA @check_objects.sql >> Report.txt 
    echo ***** >> Report.txt 
) 

set "Server[%1]=" 
if defined Next shift & goto Process 
goto :eof 

:End 
endlocal 
pause >nul 

check_objects.sql

Spool check_objects.sql 

select OBJECT_NAME || ' ' || OBJECT_TYPE 
from dba_objects 
where status = 'INVALID' 
/
+0

第一個代碼blurb看起來像一個Windows批處理文件,對嗎?你可以添加一個你試圖避免的「連接信息」的例子嗎? – runningviolent

+0

SQL * Plus:版本11.2.0.1.0生產週四11月24日17:58:54 2016 版權所有(c)1982,2010,Oracle。版權所有。 是的,第一個是批處理文件。 連接到: Oracle數據庫12c的企業版發行12.1.0.2.0 - 64位生產 隨着分區,OLAP,高級分析和實時應用測試選項 沒有行選擇 消逝:00:00:00.06 SQL>與Oracle Database 12c企業版版本12.1.0.2.0斷開 - 64位生產 使用分區,OLAP,高級分析和實際應用程序測試選項 – prokopis

+0

Martin正確無誤。嘗試添加-s參數到您的sqlplus命令。 – runningviolent

回答