Automate Activity Report Downloads to a Local Computer

Use the script in this section to automate the downloading of Activity Reports from an environment to a local computer.

You use syncAprReports.bat to download Activity Reports. You can schedule the batch file using Windows scheduler to automate the downloading of Activity Reports. See Using Activity Reports and Access Logs to Monitor Usage in Getting Started with Oracle Enterprise Performance Management Cloud for Administrators for detailed information about Activity Report.

You manually create syncAprReports.bat by copying the script provided in the following procedure and then updating the connection parameters. This script checks the environment and downloads only the reports that are more recent than those available in the download directory on the local computer.

Note:

  • The script is to be run from a Windows computer only.
  • This script does not download the Feedback Activity Report, which is generated when users submit feedback.
  • If the password you use contains special characters, see Handling Special Characters
  1. Create a batch (.BAT) file named syncAprReports.bat containing the following script and save it in a convenient location, for example, 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. Modify syncAprReports.bat to set the values for the parameters in the following table. These values are used to access the environment to download Activity Reports.

    Table 3-3 Parameter Values to Include in syncAprReports.bat

    Parameter Expected Value
    set apr_dir=%1 Specify an existing directory into which Activity Reports are to be downloaded.

    Example: set apr_dir="C:\Oracle\apr"

    set username=%2 An Oracle Enterprise Performance Management Cloud user name that is to be used to sign into the environment to download Activity Reports.

    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 the encrypt command for information on creating an encrypted password file.

    Examples:

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

    set password="Ex@mple1"

    set url=%4 The URL of the environment.

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

  3. Using Windows Scheduler, schedule syncAprReports.bat. See Automating Script Execution for detailed steps.