自動將活動報表下載至本機電腦

使用本節中的指令碼,以自動將「活動報表」從環境下載到本機電腦。

使用 syncAprReports.bat 以下載活動報表。您可以使用 Windows 排程器以排程批次檔案,以自動下載活動報表。如需關於活動報表的詳細資訊,請參閱使用活動報表與存取日誌監視使用狀況 in 管理員適用的 Oracle Enterprise Performance Management Cloud 快速入門

您可以藉由複製下列程序中提供的指令碼,然後更新連線參數,以手動建立 syncAprReports.bat。此指令碼會檢查環境,並僅下載比本機電腦之下載目錄中可用報表更新的報表。

註:

  • 該指令碼僅從 Windows 電腦執行。
  • 此指令碼不會下載使用者提交意見時產生的意見活動報表。
  • 如果密碼包含特殊字元,請參閱處理特殊字元
  1. 建立名稱為 syncAprReports.bat 的批次 (.BAT) 檔案,其包含下列指令碼,並將其儲存在方便的位置,例如,C:\automate_scripts
    @echo off
    title APR
    setlocal DisableDelayedExpansion
    
    REM To hardcode the values in the script replace %1, %2, %3, and %4, with the actual values.
    REM Example:
    REM set apr_dir="C:\Oracle\apr"
    REM set username="serviceAdmin"
    REM set password="Ex@mple!"
    REM set url="https://test-example.stg-pbcs.us1.oraclecloud.com"
    set apr_dir=%1
    set username=%2
    set password=%3
    set url=%4
    setlocal EnableDelayedExpansion
    set epmautomate_dir=%cd%
    set lastfile=
    set argC=0
    for %%x in (%*) do Set /A argC+=1
    if %argC% neq 0 (
            if %argC% neq 3 (
                    if %argC% neq 4 (
                            goto :usage
                    )
            )
    )
    goto :login
    :usage
    echo.
    echo Invalid syntax. Please check the parameters. 
    echo Syntax:
    echo 1) syncAprReports.bat APR_FolderPath_on_client username password url
    echo     or 
    echo 2) set the parameters in the file and use below syntax
    echo    syncAprReports.bat
    goto :end
    
    :login
    setlocal DisableDelayedExpansion
    for /f "delims=" %%i in ('epmautomate login %username% %password% %url%') do set result=%%i
    if "Login successful" neq "%result%" (
            echo Login Failed
            goto :end
    ) 
    
    if not exist %apr_dir% (
    echo.
    echo apr folder does not exist 
    GOTO :end
    )
    cd /D %apr_dir%
    for /f "delims=" %%D in ('dir /a:d /b /o:-n') do ( 
    REM AFTER: for /f "delims=" %%D in ('dir /a-d /b /s /o:-n') do (
            set "lastFile=%%~nD"
            goto :next
    )
    
    :next
    setlocal EnableDelayedExpansion
    echo.
    echo Most Recent APR on client is %lastFile%
    
    set "output_cnt=0"
    cd /D %epmautomate_dir%
    for /F "delims=" %%f in ('epmautomate listfiles') do (
    
            cd /D !apr_dir!
            set "line=%%f"
            for /f "tokens=* delims= " %%a in ("!line!") do set line=%%a
            if "!line:~0,3!" equ "apr" (
    
                    if "!line:~4,8!" neq "Feedback" (
    
                            set isValidFile=false
                            if "!line:~-5!" equ ".html" set isValidFile=true
                            if "!line:~-5!" equ ".json" set isValidFile=true
    
                            if "!isValidFile!" equ "true" (
                                    
                                    if "%lastFile%" lss "!line:~4,19!" (
                                            
                                                    if "!line:~4,19!" neq "!dirname!" (
                                                            
                                                            set apr_dir=!apr_dir:"=!
                                                            set /a output_cnt+=1
                                                            set "output[!output_cnt!]=!apr_dir!\!line:~4,19!"
                                                            set "dirname=!line:~4,19!"
                                                            
                                                            REM start downloading
                                                            mkdir "!dirname!"
                                                            cd /D !dirname!
                                                            echo downloading !line!
                                                            set "downloadDir=!apr_dir!\!dirname!"
                                                                                    
                                                            cd /D %epmautomate_dir%
                                                            for /f "delims=" %%i in ('epmautomate downloadfile "!line!"') do set result1=%%i
                                                            move "!line:~24!" "!downloadDir!" > nul
                                                            echo !result1!
                                                            REM end downloading
                                                            
                                                    ) else (
                                                    
                                                            REM start downloading
                                                            cd /D !dirname!
                                                            echo downloading !line!
                                                            set apr_dir=!apr_dir:"=!
                                                            set "downloadDir=!apr_dir!\!dirname!"
                                                            cd /D %epmautomate_dir%
                                                            for /f "delims=" %%i in ('epmautomate downloadfile "!line!"') do set result1=%%i
                                                            move "!line:~24!" "!downloadDir!" > nul
                                                            echo !result1!
                                                            REM end downloading
                                                            
                                                    )
                                    ) else (
                                    
                                            REM TO-DO
                                            
                                    )
                            )
                    )
            )
    )
    
    echo.
    echo %output_cnt% APR's downloaded
    for /L %%n in (1 1 !output_cnt!) DO echo !output[%%n]!
    goto :end
    
    :end
    cd /D %epmautomate_dir%
    endlocal
  2. 修改 syncAprReports.bat 以設定下表中參數的值。這些值用於存取環境以下載活動報表。

    表格 3-3 要包含在 syncAprReports.bat 中的參數值

    Parameter 預期值
    set apr_dir=%1 指定要下載活動報表的現有目錄。

    範例: set apr_dir="C:\Oracle\apr"

    set username=%2 用於登入環境以下載活動報表的 Oracle Enterprise Performance Management Cloud 使用者名稱。

    範例: set username="ServiceAdmin"

    set password=%3

    儲存由 username 變數指定之使用者的加密密碼的檔案名稱和位置。您也可以指定使用者的純文字密碼 (不建議)。如需建立加密密碼檔案的相關資訊,請參閱 encrypt 命令。

    範例:

    set password="C:\mySecuredir\password.epw"

    set password="Ex@mple1"

    set url=%4 環境的 URL。

    範例:set url="https://test-example.stg-pbcs.us1.oraclecloud.com"

  3. 使用 Windows 排程器,排程 syncAprReports.bat。如需瞭解詳細步驟,請參閱自動執行指令碼