我正在尝试制作一个自动检查所有客户的批处理脚本 如果存在无效对象,则在数据库中。
我遇到的问题是,当我尝试打印结果时,.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 :(得分:1)
尝试sqlplus -s 还想检查一下: https://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12040.htm
问候。