使用本节中的脚本可自动将访问日志从环境中下载到本地计算机。
您可以使用 Windows 计划程序来调度 syncAccessLog.bat
以自动执行日志文件的下载。有关使用应用程序管理下载访问日志的过程,请参阅《Oracle Enterprise Performance Management Cloud 管理员入门》中的“查看和下载活动报表和访问日志”。
以下脚本将检查环境,且只下载比本地计算机下载目录中的日志文件更新的日志文件。这是 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 Enterprise Performance Management Cloud 用户名。
示例: |
set password=%3 |
用于存储由 示例:
|
set url=%4 |
环境的 URL。
示例: |
syncAccessLog.bat
。有关详细步骤,请参阅“自动执行脚本”。