I’m after a bit of help if possible with the powershell script attached in the email below please.
I have a script that I am trying to run on a windows server which is reporting on jobs running in autosys in the previous 24 hours. The job is failing in the step to pick out the jobs run from input file C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-full-PRD and put them to C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp1 is it just returning a null value. It should be picking out any jobs run between 05/08/2024 07:00 - 06/08/2024 07:00 and outputting them to C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp1. The bit of the code with the issue is below if anybody could advise why it is not picking the matching lines out at all please.
An extract from the input file
PRD_PHOENIX_TEST_GLKCL0058V 08/06/2024 06:00:01 08/06/2024 06:00:01 FA 98554/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/06/2024 11:15:01 08/06/2024 11:15:01 SU 98849/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/06/2024 04:00:01 08/06/2024 04:00:01 FA 98456/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/06/2024 10:15:01 08/06/2024 10:15:02 SU 98790/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/06/2024 02:00:01 08/06/2024 02:00:02 FA 98359/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/06/2024 09:15:01 08/06/2024 09:15:01 SU 98731/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/05/2024 22:00:02 08/05/2024 22:00:02 FA 98188/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/06/2024 08:15:01 08/06/2024 08:15:01 SU 98672/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/05/2024 21:25:00 08/05/2024 21:25:00 FA 98172/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/06/2024 07:15:01 08/06/2024 07:15:01 SU 98616/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/05/2024 06:00:01 08/05/2024 06:00:01 FA 97313/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/06/2024 06:15:01 08/06/2024 06:15:01 SU 98565/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/05/2024 04:00:00 08/05/2024 04:00:01 FA 97215/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/06/2024 05:15:01 08/06/2024 05:15:01 SU 98513/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/05/2024 02:00:01 08/05/2024 02:00:02 FA 97118/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/06/2024 04:15:00 08/06/2024 04:15:01 SU 98465/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/04/2024 22:00:00 08/04/2024 22:00:00 FA 96947/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/06/2024 03:15:01 08/06/2024 03:15:01 SU 98418/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/04/2024 21:25:00 08/04/2024 21:25:00 FA 96931/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/06/2024 02:15:01 08/06/2024 02:15:01 SU 98370/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/04/2024 06:00:01 08/04/2024 06:00:01 FA 96267/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/06/2024 01:15:00 08/06/2024 01:15:00 SU 98321/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/04/2024 04:00:01 08/04/2024 04:00:01 FA 96188/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/06/2024 00:15:00 08/06/2024 00:15:01 SU 98273/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/04/2024 02:00:01 08/04/2024 02:00:03 FA 96107/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 23:15:00 08/05/2024 23:15:01 SU 98215/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/03/2024 22:00:00 08/03/2024 22:00:00 FA 95939/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 22:15:00 08/05/2024 22:15:01 SU 98193/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/03/2024 21:25:00 08/03/2024 21:25:00 FA 95916/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 21:15:01 08/05/2024 21:15:01 SU 98171/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/03/2024 06:00:01 08/03/2024 06:00:01 FA 95230/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 20:15:01 08/05/2024 20:15:01 SU 98149/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/03/2024 04:00:01 08/03/2024 04:00:03 FA 95151/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 19:15:00 08/05/2024 19:15:00 SU 98120/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/03/2024 02:00:01 08/03/2024 02:00:03 FA 95070/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 18:15:02 08/05/2024 18:15:02 SU 98078/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/02/2024 22:00:01 08/02/2024 22:00:01 FA 94924/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 17:15:01 08/05/2024 17:15:01 SU 98017/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/02/2024 21:25:00 08/02/2024 21:25:01 FA 94908/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 16:15:01 08/05/2024 16:15:01 SU 97938/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/02/2024 06:00:01 08/02/2024 06:00:01 FA 94124/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 15:15:01 08/05/2024 15:15:02 SU 97859/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/02/2024 04:00:01 08/02/2024 04:00:01 FA 94026/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 14:15:00 08/05/2024 14:15:01 SU 97788/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/02/2024 02:00:02 08/02/2024 02:00:03 FA 93929/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 13:15:00 08/05/2024 13:15:01 SU 97729/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/01/2024 22:00:01 08/01/2024 22:00:02 FA 93759/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 12:15:02 08/05/2024 12:15:02 SU 97668/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/01/2024 21:25:01 08/01/2024 21:25:01 FA 93743/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 11:15:01 08/05/2024 11:15:01 SU 97609/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/01/2024 06:00:01 08/01/2024 06:00:01 FA 92956/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 10:15:01 08/05/2024 10:15:01 SU 97550/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/01/2024 04:00:01 08/01/2024 04:00:01 FA 92858/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 09:15:00 08/05/2024 09:15:01 SU 97491/1 0
PRD_PHOENIX_TEST_GLKCL0058V 08/01/2024 02:00:01 08/01/2024 02:00:02 FA 92761/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 08:15:01 08/05/2024 08:15:01 SU 97432/1 0
PRD_PHOENIX_TEST_GLKCL0058V 07/31/2024 22:00:01 07/31/2024 22:00:01 FA 92592/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 07:15:01 08/05/2024 07:15:01 SU 97376/1 0
PRD_PHOENIX_TEST_GLKCL0058V 07/31/2024 21:29:33 07/31/2024 21:29:33 FA 92576/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 06:15:01 08/05/2024 06:15:01 SU 97324/1 0
PRD_PHOENIX_TEST_GLKCL0058V 07/31/2024 21:25:00 07/31/2024 21:25:00 FA 92573/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 05:15:01 08/05/2024 05:15:01 SU 97272/1 0
PRD_PHOENIX_TEST_GLKCL0058V 07/31/2024 16:09:31 07/31/2024 16:09:32 FA 92367/1 1953
PRD_PHOENIX_LN_CYCLICS_TEST_GLKCL0058V 08/05/2024 04:15:00 08/05/2024 04:15:00 SU 97224/1 0
The code which should pick out the matching lines
`
Preformatted text`# Extract the reporting period ONLY data
$reportHours = 7..23 + 0..6
foreach ($hour in $reportHours) {
$timeFrame = if ($hour -lt 10) { "$SDATE 0$hour" } else { "$SDATE $hour" }
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-full-PRD" | Where-Object { $_ -like "$timeframe" } | Out-File -Append "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp1"
Below is the full script
# PowerShell script to automate the Daily Workload Automation AE report for GROUP: PHOENIX jobs
# This script generates reports for jobs started during the previous day and saves them in a specific folder structure.
# Set environmental variables
$env:AUTOSYS = "D:\Applications\CA\WorkloadAutomationAE\autosys"
$env:AUTOUSER = "D:\Applications\CA\WorkloadAutomationAE\autouser.MAS"
$env:AUTOSERV = "MAS"
$env:LD_LIBRARY_PATH = "D:\Applications\CA\WorkloadAutomationAE\autosys\lib;$env:LD_LIBRARY_PATH"
$env:PATH = "D:\Applications\CA\WorkloadAutomationAE\autosys\bin;D:\Applications\CA\SharedComponents\Csam\SockAdapter\\bin;D:\Applications\CA\SharedComponents\Csam\SockAdapter\\bin64;D:\Applications\CA\WorkloadAutomationAE\JRE_WA\bin;D:\Applications\CA\WorkloadAutomationAE\perl\bin;%PATH%;"
# Set date variables
$yesterday = (Get-Date).AddDays(-1)
$today = Get-Date
$SDATE = $yesterday.ToString("dd/MM/yyyy")
$TDATE = $today.ToString("dd/MM/yyyy")
$DAY = $yesterday.ToString("dd")
$MONTHN = $yesterday.ToString("MMM")
$MONTH = $yesterday.ToString("MM")
$YEAR = $yesterday.ToString("yyyy")
# Check for input parameter for start date
if ($args.Count -gt 0) {
$SDATE = $args[0]
}
# Create new month folder if needed
$reportDir = "C:\AutosysScripts\PROD\LN-DLY-REPORTS\$YEAR-$MONTH_$MONTHN"
if (-not (Test-Path $reportDir)) {
New-Item -ItemType Directory -Path $reportDir
}
# Define output file paths
$TEXTFILEN = "$reportDir\$YEAR-$MONTH-$DAY_NONCYCLICS.txt"
$TEXTFILEC = "$reportDir\$YEAR-$MONTH-$DAY_CYCLICS.txt"
$TEXTFILEA = "$reportDir\$YEAR-$MONTH-$DAY_APPS.txt"
# Remove temp files from previous run
$tempFiles = @("temp1", "temp-full", "temp-n", "temp-nn", "temp-c", "temp-a", "temp-aa", "temp-out-n", "temp-out-c", "temp-out-a", "temp-cyc1", "temp-cyc2", "temp-cyc3", "Attachment-1", "Attachment-2", "Attachment-3")
foreach ($file in $tempFiles) {
$filePath = "C:\AutosysScripts\PROD\LN-DLY-REPORTS\$file"
if (Test-Path $filePath) {
Remove-Item $filePath
}
}
# Write NONCYCLICS report header
@"
----------------------------------------------------------------------------------
Group: PHOENIX - LN Job report for time frame $SDATE 07:00 to $TDATE 07:00
----------------------------------------------------------------------------------
N O N - C Y C L I C J O B S
----------------------------------------------------------------------------------
Job Name Last Start Last End ST Run/Vers RC Duration
________________________________________________________________ ___________________ ___________________ __ _________ ___ ________
"@ | Out-File -FilePath $TEXTFILEN
# Write CYCLICS report header
@"
----------------------------------------------------------------------------------
Group: PHOENIX - LN Job report for time frame $SDATE 07:00 to $TDATE 07:00
----------------------------------------------------------------------------------
C Y C L I C J O B S
----------------------------------------------------------------------------------
Job Name Last Start Last End ST Run/Vers RC Duration
________________________________________________________________ __________________ ___________________ __ ________ ___ ________
"@ | Out-File -FilePath $TEXTFILEC
# Write APPS report header
@"
------------------------------------------------------------------------------------
Group: PHOENIX - APPS Job report for time frame $SDATE 07:00 to $TDATE 07:00
------------------------------------------------------------------------------------
A P P S J O B S
------------------------------------------------------------------------------------
Job Name Last Start Last End ST Run/Vers RC Duration
________________________________________________________________ ____________________ ___________________ __ ________ ___ ________
"@ | Out-File -FilePath $TEXTFILEA
# Issue autorep to extract jobrun details (sorted on jobname)
& autorep -J PRD_PHOENIX* | Out-File -FilePath "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-full"
# Clean up the temp-full file to PRD ONLY minus the BOXES
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-full" | Where-Object { $_ -match "PRD" -and $_ -notmatch "_BOX_" } | Out-File "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-full-PRD"
# Extract the reporting period ONLY data
$reportHours = 7..23 + 0..6
foreach ($hour in $reportHours) {
$timeFrame = if ($hour -lt 10) { "$SDATE 0$hour" } else { "$SDATE $hour" }
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-full-PRD" | Where-Object { $_ -like "$timeframe" } | Out-File -Append "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp1"
}
# Remove all cyclic jobs and BOXES from temp1 and write to temp-n
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp1" | Where-Object { $_ -notmatch '(_CYCLICS_|_BOX_)' } | Out-File "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-n"
# Format temp-n for APPS elapse times
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-n" | ForEach-Object {
"{0,-64} {1,10} {2,8} {3,10} {4,8} {5,2} {6,7} {7,-3}" -f $_.Substring(0, 64), $_.Substring(65, 10), $_.Substring(76, 8), $_.Substring(85, 10), $_.Substring(96, 8), $_.Substring(105, 2), $_.Substring(107, 7), $_.Substring(114, 3)
} | Out-File "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-nn"
# Remove all cyclic and LN and BOXES from temp1 and write to temp-a
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp1" | Where-Object { $_ -notmatch '(_CYCLICS_|_LN_|_BOX_)' } | Out-File "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-a"
# Format temp-a for APPS elapse times
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-a" | ForEach-Object {
"{0,-64} {1,10} {2,8} {3,10} {4,8} {5,2} {6,7} {7,-3}" -f $_.Substring(0, 64), $_.Substring(65, 10), $_.Substring(76, 8), $_.Substring(85, 10), $_.Substring(96, 8), $_.Substring(105, 2), $_.Substring(107, 7), $_.Substring(114, 3)
} | Out-File "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-aa"
# Issue autorep to extract jobrun details of cyclics
for ($n = 0; $n -lt 110; $n++) {
& autorep -J "PRD_PHOENIX_LN_CYCLICS_*" -R -$n | Out-File -Append "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-cyc1"
}
# Clean up the extracted CYCLIC data
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-cyc1" | Where-Object { $_ -match "_LN_" -and $_ -notmatch "Was not" -and $_ -notmatch "_BOX_" } | Out-File "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-cyc2"
# Format temp-cyc2 for elapse times
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-cyc2" | ForEach-Object {
"{0,-64} {1,10} {2,8} {3,10} {4,8} {5,2} {6,7} {7,-3}" -f $_.Substring(0, 64), $_.Substring(65, 10), $_.Substring(76, 8), $_.Substring(85, 10), $_.Substring(96, 8), $_.Substring(105, 2), $_.Substring(107, 7), $_.Substring(114, 3)
} | Out-File "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-cyc3"
# Select only those cyclic jobs which have run since 06:00 yesterday
foreach ($hour in $reportHours) {
$timeFrame = if ($hour -lt 10) { "$SDATE 0$hour" } else { "$SDATE $hour" }
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-cyc3" | Where-Object { $_ -like "*$timeFrame*" } | Out-File -Append "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-c"
}
# Function to calculate elapse time
function Calculate-ElapseTime {
param (
[string]$line
)
$elapse = ""
$sd = $line.Substring(66, 2)
$sm = $line.Substring(69, 2)
$sy = $line.Substring(72, 4)
$sh = $line.Substring(77, 2)
$si = $line.Substring(80, 2)
$ss = $line.Substring(83, 2)
$ed = $line.Substring(87, 2)
$em = $line.Substring(90, 2)
$ey = $line.Substring(93, 4)
$eh = $line.Substring(98, 2)
$ei = $line.Substring(101, 2)
$es = $line.Substring(104, 2)
if ($ed -ne "--") {
$sec_s = [datetime]::Parse("$sy-$sm-$sd $sh.$si.$ss").Ticks / 10000000
$sec_e = [datetime]::Parse("$ey-$em-$ed $eh.$ei.$es").Ticks / 10000000
$sec_diff = $sec_e - $sec_s
$h_diff = [math]::Floor($sec_diff / 3600)
$s_diffo = $sec_diff % 3600
$m_diff = [math]::Floor($s_diffo / 60)
$s_diff = $s_diffo % 60
$elapse = "{0:D2}:{1:D2}:{2:D2}" -f $h_diff, $m_diff, $s_diff
}
return "$line $elapse"
}
# Calculate elapse time for NONCYCLICS
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-nn" | ForEach-Object {
Calculate-ElapseTime $_
} | Out-File "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-out-n"
# Calculate elapse time for CYCLICS
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-c" | ForEach-Object {
Calculate-ElapseTime $_
} | Out-File "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-out-c"
# Calculate elapse time for APPS
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-aa" | ForEach-Object {
Calculate-ElapseTime $_
} | Out-File "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-out-a"
# Write records to textfiles (non-cyclics)
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-out-n" | Where-Object { $_ -match "LN" } | Sort-Object | Out-File -Append $TEXTFILEN
# Write records to textfiles (cyclic)
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-out-c" | Where-Object { $_ -match "LN" } | Sort-Object | Out-File -Append $TEXTFILEC
# Write records to textfiles (APPS)
Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-out-a" | Sort-Object | Out-File -Append $TEXTFILEA
# Write report trailer (non-cyclics)
@"
__________________________________________________________________________________________________________________________________________
Status Codes (ST)
-----------------
AC (ACTIVATED) : FA (FAILURE) : IN (INACTIVE) : OH (ON_HOLD) : OI (ON_ICE) : PE (PEND_MACH) : QU (QUE_WAIT)
RE (RESTART) : RU (RUNNING) : RW (RESWAIT) : ST (STARTING) : SU (SUCCESS) : TE (TERMINATED)
__________________________________________________________________________________________________________________________________________
"@ | Out-File -Append $TEXTFILEN
# Count failures for non-cyclic jobs
$failcountn = (Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-out-n" | Where-Object { $_ -notmatch "_BOX_" -and $_ -match " FA " }).Count
"Number of non-cyclic jobs with status FAILURE: $failcountn" | Out-File -Append $TEXTFILEN
# Write report trailer (cyclics)
@"
__________________________________________________________________________________________________________________________________________
Status Codes (ST)
-----------------
AC (ACTIVATED) : FA (FAILURE) : IN (INACTIVE) : OH (ON_HOLD) : OI (ON_ICE) : PE (PEND_MACH) : QU (QUE_WAIT)
RE (RESTART) : RU (RUNNING) : RW (RESWAIT) : ST (STARTING) : SU (SUCCESS) : TE (TERMINATED)
__________________________________________________________________________________________________________________________________________
"@ | Out-File -Append $TEXTFILEC
# Count failures for cyclic jobs
$failcountc = (Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-out-c" | Where-Object { $_ -notmatch "_BOX_" -and $_ -match " FA " }).Count
"Number of cyclic jobs with status FAILURE: $failcountc" | Out-File -Append $TEXTFILEC
# Write report trailer (APPS)
@"
__________________________________________________________________________________________________________________________________________
Status Codes (ST)
-----------------
AC (ACTIVATED) : FA (FAILURE) : IN (INACTIVE) : OH (ON_HOLD) : OI (ON_ICE) : PE (PEND_MACH) : QU (QUE_WAIT)
RE (RESTART) : RU (RUNNING) : RW (RESWAIT) : ST (STARTING) : SU (SUCCESS) : TE (TERMINATED)
__________________________________________________________________________________________________________________________________________
"@ | Out-File -Append $TEXTFILEA
# Count failures for APPS jobs
$failcounta = (Get-Content "C:\AutosysScripts\PROD\LN-DLY-REPORTS\temp-out-a" | Where-Object { $_ -notmatch "_BOX_" -and $_ -match " FA " }).Count
"Number of cyclic jobs with status FAILURE: $failcounta" | Out-File -Append $TEXTFILEA
# Write TEXTFILEN and TEXTFILEC and TEXTFILEA to stdout
Get-Content $TEXTFILEN
Get-Content $TEXTFILEC
Get-Content $TEXTFILEA
# Write Mail text body header
@"
Group: PHOENIX - LN Job report for time frame $SDATE 07:00 to $TDATE 07:00
"@ | Out-File -FilePath "C:\AutosysScripts\PROD\scripts\LN-Daily-Job-Report-hdr"
# Send email with attachments
$subject = "BAE - Daily PHOENIX LN Job Report $SDATE 07:00 - $TDATE 07:00"
$distrib = "pnixon@dxc.com"
if (-not [string]::IsNullOrEmpty($distrib)) {
# Copy the TEXTFILEN and TEXTFILEC and TEXTFILEA constructed data to a permanent file
Copy-Item $TEXTFILEN "C:\AutosysScripts\PROD\LN-DLY-REPORTS\Attachment-1"
Copy-Item $TEXTFILEC "C:\AutosysScripts\PROD\LN-DLY-REPORTS\Attachment-2"
Copy-Item $TEXTFILEA "C:\AutosysScripts\PROD\LN-DLY-REPORTS\Attachment-3"
#~ # Convert files from UNIX to DOS
# & unix2dos "C:\AutosysScripts\PROD\LN-DLY-REPORTS\Attachment-1"
# & unix2dos "C:\AutosysScripts\PROD\LN-DLY-REPORTS\Attachment-2"
# & unix2dos "C:\AutosysScripts\PROD\LN-DLY-REPORTS\Attachment-3"
# Create and send the Email
$emailBody = Get-Content "C:\AutosysScripts\PROD\scripts\LN-Daily-Job-Report-hdr"
$attachments = @("C:\AutosysScripts\PROD\LN-DLY-REPORTS\Attachment-1", "C:\AutosysScripts\PROD\LN-DLY-REPORTS\Attachment-2", "C:\AutosysScripts\PROD\LN-DLY-REPORTS\Attachment-3")
Send-MailMessage -To $distrib -From AutosysAdmin@baesystems.com -Subject $subject -Body $emailBody -Attachments $attachments -SmtpServer apprelay.greenlnk.net
}
type or paste code here