Find and Download Files from an Oracle EPM Cloud Environment
In this Blog lets see the example script to automate the process of downloading files from an Oracle Enterprise Performance Management Cloud environment using a text string as a wildcard.
This
script matches the string specified in the FILENAME parameter with file names
displayed using the listfiles command, then automatically downloads the
matching files.
Ensure you set the appropriate search string to the FILENAME parameter. For example, FILENAME="Scheduler Output/epm" will match file names containing "Scheduler Output/epm" in the listfiles command output, identifying the files to download.
The
script requires the following input parameters: username, password or
password_file, and service_url.
Detailed
Explanation
- Purpose:
The script helps automate the downloading of files from an Oracle EPM
Cloud environment by using a wildcard text string.
- Functionality:
- It uses
the listfiles command to display all file names in the environment.
- It
matches these file names against a specified string in the FILENAME
parameter.
- It
automatically downloads the files that match the string.
- Usage:
- Assign
an appropriate string to the FILENAME parameter to specify the pattern
you want to match. For example, setting FILENAME="Scheduler
Output/epm" will look for file names that include "Scheduler
Output/epm".
- Parameters:
- username:
Your Oracle EPM Cloud environment username.
- password
or password_file: Your password or a file containing your password.
- service_url:
The URL of your Oracle EPM Cloud service.
- Example:
If you want to download files related to scheduler output, you would set
FILENAME to "Scheduler Output/epm", and the script will find and
download all files with names containing this string.
This script streamlines the file retrieval process, making it efficient and less error-prone by automating file searching and downloading tasks.
Windows batch file Example
@echo off
setlocal EnableExtensions EnableDelayedExpansion
set USERNAME="username"
set PASSWORD="password"
set URL="url"
call epmautomate login %USERNAME% %PASSWORD% %URL%
set FILENAME="Scheduler Output/epm"
for /f "tokens=*" %%i in ('epmautomate listfiles ^| findstr /b /r /c:"^ *%FILENAME%" ') do (
call epmautomate downloadfile "%%i"
)
call epmautomate logout
endlocal
PowerShell Example: (Like the above batch file provided by Oracle its is done using the PowerShell)
# Define variables
$env:PATH += ";C:\oracle\EPM Automate\bin"
$pwds = "Password"
$logs = "C:\Users\E106573\Documents\logs"
$URL = "https://test-oraclecloud.com"
# Function to run epmautomate and capture output
function Run-EpmAutomate {
param (
[string]$command,
[string]$outputLog
)
Start-Process -NoNewWindow -FilePath "epmautomate" -ArgumentList $command -RedirectStandardOutput $outputLog -Wait -PassThru | Out-Null
Get-Content -Path $outputLog
}
# Login to EPM
$loginLog = "$logs\login.log"
Write-Output "Login Output:"
Run-EpmAutomate "login dayalan@example.com
$pwds $URL" $loginLog
# List files to verify the file existence
$listFilesLog = "$logs\listFiles.log"
Run-EpmAutomate "listfiles" $listFilesLog | Out-Null
# Read the contents of the listFiles.log for diagnostics
$listFilesContent = Get-Content -Path $listFilesLog
# Parse the list of files to find the file that matches the pattern
$filePattern = "outbox/PCM Outbound Data_*"
$fileToDownload = $listFilesContent | Select-String -Pattern $filePattern
| ForEach-Object { $_.Line.Trim() } | Sort-Object -Property { [int]($_ -replace
'\D', '') } | Select-Object -Last 1
if ($fileToDownload) {
Write-Output "Latest file found: $fileToDownload"
# Encode the file name for URL compatibility
$encodedFileToDownload = $fileToDownload -replace ' ',
'%20'
Write-Output "Encoded file name for download:
$encodedFileToDownload"
# Specify the download path
$downloadFilePath = Join-Path -Path $datafiles -ChildPath
($fileToDownload -replace 'outbox/', '' -replace ' ', '')
$downloadLog = "$logs\downloadfile.log"
Write-Output "Download File Output:"
# Run the download command with the correct arguments
Run-EpmAutomate "downloadfile
`"$fileToDownload`" `"$downloadFilePath`""
$downloadLog
# Check the download log for success
$downloadLogContent = Get-Content -Path $downloadLog
Write-Output $downloadLogContent
if ($downloadLogContent -match "completed
successfully" -or $downloadLogContent -match "downloaded to") {
if (Test-Path -Path $downloadFilePath) {
Write-Output "File
downloaded successfully to $downloadFilePath"
# Logout
$logoutLog = "$logs\logout.log"
Write-Output "Logout Output:"
Run-EpmAutomate "logout" $logoutLog
Output of the PowerShell Script:
List File Output:
The File *1786 is listed in the log & the same file is downloaded by
the program as that is the latest one.
Hope this was
useful, Happy days on the Cloud.
No comments:
Post a Comment