Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepowershell
titleForward Order Logs (Linux version)
linenumberstrue
collapsetrue
<?xml version="1.0" encoding="UTF-8" ?>
<job title="Forward Order Logs" process_class="agent_linux">
  <params>
    <param name="history_results_directory" value="/tmp/history"/>
  </params>
  <script language="shell"><![CDATA[
pwsh -NoLogo -NonInteractive -Command '& {
    . $env:SCHEDULER_DATA/config/powershell/JobScheduler.PowerShell_profile.ps1;
    Import-Module $env:SCHEDULER_DATA/config/powershell/Modules/JobScheduler;
    Connect-JS -Url $JOCCockpitUrl -Credential $JOCCockpitCredential | Out-Null;
 
    New-Item -ItemType Directory -Force -Path $env:SCHEDULER_PARAM_HISTORY_RESULTS_DIRECTORY | Out-Null;

    # retrieve last history results if available
    if ( Test-Path -Path "$($env:SCHEDULER_PARAM_HISTORY_RESULTS_DIRECTORY)/order.history" -ErrorAction continue )
    {
        $lastHistory = Import-Clixml -Path "$($env:SCHEDULER_PARAM_HISTORY_RESULTS_DIRECTORY)/order.history";
   } else {
        $lastHistory = Get-JobSchedulerOrderHistory -RelativeDateFrom -8h | Sort-Object -Property startTime;
    }
 
    # Copy log files to target directory
    Get-JSOrderHistory -DateFrom $lastHistory[0].startTime | Tee-Object -Variable lastHistory | Get-JobSchedulerOrderLog | Select-Object @{name="path"; expression={ "$env:SCHEDULER_PARAM_HISTORY_RESULTS_DIRECTORY/$(Get-Date $_.startTime -f 'yyyyMMdd-hhmmss')-$([io.path]::GetFileNameWithoutExtension($_.jobChain))-$($_.orderId).log"}}, @{name="value"; expression={ $_.log }} | Set-Content;
 
    # store last history results to a file for later retrieval
    $lastHistory | Export-Clixml -Path "$env:SCHEDULER_PARAM_HISTORY_RESULTS_DIRECTORY/order.history";
                 
    Write-Output ".. logs forwarded to: $env:SCHEDULER_PARAM_HISTORY_RESULTS_DIRECTORY";
}'
]]></script>
  <run_time/>
</job>
</job>

...

  • Basically the same explanations as for the Windows version of the job apply.
  • Line 7: The PowerShell has to be invoked with pwsh. Consider that any subsequent PowerShell commands are quoted within a string that starts with line 3 7 and that ends with line 29. 
    • As the string is using a single quote all subsequent PowerShell commands make use of double quotes when required.
    • You could apply a different quoting style, however, quotes have to be consistent.
  • Line 8: As an example a PowerShell profile is invoked that provides the variables for URL and credentials to access the JOC Cockpit REST Web Service. Such profiles can be stored in different locations and can be invoked automatically by pwsh on startup.

...