Download Access Logs from an Environment
Use the script in this section to automate the process of downloading access logs from an environment to a local computer.
You can schedule syncAccessLog.bat
using Windows scheduler to automate the downloading of the log files. See Viewing and Downloading Activity Reports and Access Logs in Getting Started Guide for Administrators for procedures to download access logs using Application Management.
The following script checks the environment and downloads only the log files that are more recent than those available in the download directory on the local computer. The is a Windows script; you can create a similar shell script for Linux/UNIX environments.
- Create a batch (.BAT) file named
syncAccessLog.bat
containing the following script and save it in a convenient location, for example,C:\automate_scripts
.Note:
If your password contains special characters, see Handling Special Characters.@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
- Modify
syncAccessLog.bat
to set the values for the parameters in the following table. These values are used to access the environment to download access logs.Table 3-4 Variable Values to Include in
syncAccessLog.bat
Variable Expected Value set apr_dir=%1
Specify the directory into which access logs are to be downloaded. Example:
set apr_dir="C:\Oracle\apr"
set username=%2
An Oracle Fusion Cloud Enterprise Performance Management user name that is to be used to sign into the environment to download access logs. Example:
set username="ServiceAdmin"
set password=%3
The name and location of the file that stores the encrypted password of the user specified by the
username
variable. You may also specify the plain text password of the user (not recommended). See theencrypt
command for information on creating an encrypted password file.Examples:
set password="C:\mySecuredir\password.epw"
set password="P@ssword1"
set url=%4
The URL of the environment. Example:
set url="https://test-cloudpln.pbcs.us1.oraclecloud.com"
- Using Windows Scheduler, schedule
syncAccessLog.bat
. See Automating Script Execution for detailed steps.