使用本節中的指令碼,以自動執行將存取日誌從環境下載到本機電腦的程序。
您可以使用 Windows 排程器來排定 syncAccessLog.bat,以自動下載日誌檔。如需使用應用程式管理下載存取日誌的程序,請參閱管理員適用的入門手冊中的檢視和下載活動報表與存取日誌。
下列指令碼會檢查環境,並僅下載比本機電腦之下載目錄中可用的日誌檔更新的日誌檔。這是 Windows 指令碼;您可以為 Linux/UNIX 環境建立類似的 Shell 指令碼。
syncAccessLog.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="C:\mySecuredir\password.epw"
REM set url="https://test-cloudpln.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=
REM if [%1]==[] goto :usage
REM if [%2]==[] goto :usage
REM if [%3]==[] goto :usage
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) syncAccessLog.bat APR_FolderPath_on_client username password url
echo or
echo 2) set the parameters in the file and use below syntax
echo syncAccessLog.bat
goto :end
:login
setlocal DisableDelayedExpansion
REM for /f "delims=" %%i in ('epmautomate login %2 %3 %4') do set result=%%i
for /f "delims=" %%i in ('epmautomate login %username% %password% %url%') do set result=%%i
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 Access Log 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!" equ ".zip" (
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% access logs downloaded
for /L %%n in (1 1 !output_cnt!) DO echo !output[%%n]!
goto :end
:end
cd /D %epmautomate_dir%
endlocal
syncAccessLog.bat 以設定下表中參數的值。這些值用於存取環境以下載存取日誌。
表格 3-4 要包含在 syncAccessLog.bat 中的變數值
| 變數 | 預期值 |
|---|---|
set apr_dir=%1 |
指定要下載存取日誌的目錄。
範例: |
set username=%2 |
用於登入環境以下載存取日誌的 Oracle Fusion Cloud Enterprise Performance Management 使用者名稱。
範例: |
set password=%3 |
儲存由 範例:
|
set url=%4 |
環境的 URL。
範例: |
syncAccessLog.bat。如需瞭解詳細步驟,請參閱自動執行指令碼。