We all know DRM out of the box does not have a lot of options when it comes to batch client. We depend on other tools for calling batch, error checking and email functionality.
SO if you are one of the lucky DRM guys who happens to be in-charge then here is a good tool for you. Its called Powershell. latest windows now ships with powershell which is pretty powerfull and easy to learn and implement.
here is a sample powershell script that should get you started. the script does the following.
1. Accepts Configuration File and Log File as parameters.
2. Checks if the config and log file actually exists.
3. If log file exists, it renames it with a datatime value.
4. Call the drm batch client and passes the config and log files.
5. Checks the status of the batch client.
6. Checks the log file for any errors or failures.
7. Exits with 0 for success and 1 for failure.
8. It also creates its own log showing everything it did so far.
The best part, since it depends on config file, you can use it for practically any drm batch activity (export, import, blend, action script etc).
here is the code. enjoy
----- Code starts below ----
<#
.SYNOPSIS
Runs DRM Batch Client for Exports and Action Script.
.DESCRIPTION
Generic script that calls drm batch client and passes parameters to specify export or action to be executed.
This will also check for any errors returned by the batch client.
It also searches for errors captured in the log file and returns exit status accordingly.
Note: The script can be used for all other drm batch client funcationalities like Blend,Import,queries etc. Just make sure corresponding configuration file exists.
.PARAMETER configFile LogFile
First parameter is the name of the config file that stores the configuration information of the export/action script.
Second parameter is the name of the log file where process log is stored. script uses this log to search for any errors encountered.
Process logs actions in a log file. Check the log file to find the status of each action performed.
Process return 0 for successful completion and 1 for any failures.
.EXAMPLE
Powershell .\RunDRMBatch.ps1 DRM_Hierarchy_Info.cfg DRM_Hierarchy_Info_cfg.log
#>
param( [Parameter(Mandatory=$true)]
[string] $configFile,
[Parameter(Mandatory=$true)]
[string] $LogFile)
$PSLog="D:\DRM\LOG\PSLog.log"
$ConfigPath="D:\DRM\Config"
$LogPath="D:\DRM\Log"
$drmbatchclient="C:\Oracle\Middleware\EPMSystem11R1\products\DataRelationshipManagement\client\batch-client\drm-batch-client.exe"
$DateTimeString= Get-Date -uformat %Y%m%d%H%M%S
$rtn=0
function WriteLog{
Param([string] $logstring)
$DateTimeStamp=Get-Date
if($logstring){
Add-content $PSLog -value "$DateTimeStamp - $logstring"
}
else{
Add-content $PSLog -value "$logstring"
}
}
WriteLog ""
WriteLog "**** Powershell Process Started. ****"
WriteLog "Checking for parameters passed."
if(!$ConfigFile){
WriteLog "Missing Config File Parameter. Exiting with exception."
Write-Host "Missing Config File Parameter."
throw "Missing Export Batch File Name. Please use RunDRMBatch.ps1 <config Filename> <Log FileName>."
}
if(!$LogFile){
WriteLog "Missing Log File Parameter. Exiting with exception."
Write-Host "Missing Log File Parameter."
throw "Missing Log File Name. Please use RunDRMBatch.ps1 <config Filename> <Log FileName>."
}
WriteLog "Checking if config $ConfigPath\$ConfigFile exists."
if(!(Test-Path $ConfigPath\$ConfigFile)){
WriteLog "Config File $ConfigPath\$ConfigFile does not exist. Exiting with exception."
throw "Config File $ConfigPath\$ConfigFile not found."
}
WriteLog "Checking if Log File $LogPath\$LogFile exists."
if(!(Test-Path $LogPath\$LogFile)){
WriteLog "Config File $ConfigPath\$ConfigFile does not exist.May be this is first run."
Write-Host "Log File Not found."
}
else{
WriteLog "Log File $LogPath\$LogFile exists. Attempting to rename"
write-Host "Rename the log file $LogPath\$logFile for archival purpose".
$rtn=Rename-Item $LogPath\$LogFile -NewName $LogPath\$DateTimeString"_"$LogFile -PassThru
if($rtn){
WriteLog "Renamed Log File to $rtn"
Write-Host "Renamed Successfully to $rtn"
}
else{
WriteLog "Unable to rename Log File $LogPath\$LogFile."
write-host "Rename Failed"
}
}
#call the batch client and pass parameters
WriteLog "Calling $DRMBatchClient /cfgfile=$ConfigPath\$ConfigFile /log=$LogPath\$LogFile /objectaccess=system"
Write-Host Calling "$DRMBatchClient /cfgfile=$ConfigPath\$ConfigFile /log=$LogPath\$LogFile /objectaccess=system"
&$DRMBatchClient /cfgfile=$ConfigPath\$ConfigFile /log=$LogPath\$LogFile /objectaccess=system
WriteLog "Batch Completed. Checking log file $LogPath\$LogFile for any errors."
WriteLog "Checking if log file $LogPath\$LogFile exists."
if(!(Test-Path $LogPath\$LogFile)){
WriteLog "Log File $LogPath\$LogFile does not exists.May be batch process failed."
throw "Log File $LogPath\$LogFile does not exists.May be batch process failed."
}
#check the error log to see if any errors were encountered.
Write-Host "Reading $LogPath\$LogFile to check for Error or Failure string"
if(Select-String $LogPath\$LogFile -Pattern "Error|Failure"){
WriteLog "Erros found in log file $LogPath\$LogFile. returning with exit code 1"
WriteLog "**** Process Completed. ****"
Write-Host "Erros Found $ErrorCode"
exit 1
}
else{
WriteLog "No Erros found in log file $LogPath\$LogFile. Returning successfully with exit code 0"
WriteLog "**** Process Completed. ****"
exit 0
}
--- code ends above.----
No comments:
Post a Comment