Truncate SWD_DeploymentResults.log
0 Votes |
Description
Property Details
27331 | |
QA - Ready for Production Level Testing | |
Truncate SWD_DeploymentResults.log | |
Internal | |
3/12/2024 12:00:00 AM | |
Truncate, log, SWD, SWD_DeploymentResults, reduce, logging, shorten, tail | |
True | |
eg2428 on 3/13/2024 7:48:44 AM | |
eg2428 on 3/13/2024 7:50:44 AM | |
506 Views / 2 Downloads | |
* Average over 0 ratings. ** Log In or Register to add your rating. |
Relevance
Used in 1 fixlet | * Results in a true/false |
number of lines of file "SWD_DeploymentResults.log" of folder "SWDDeployData" of folder "__Global" of data folder of client > 300
Actions
Action 1 (default)
Action Link Click
here to deploy this action.
Script Type
BigFix Action Script
parameter "mainSWDLogFolder" = "{parent folder of client folder of current site}/__Global/SWDDeployData"Success Criteria
folder create "{parameter "mainSWDLogFolder"}"
parameter "logFile" = "SWD_DeploymentResults.log"
parameter "logFolder" = "{parameter "mainSWDLogFolder"}"
parameter "logPath" = "{pathname of file "SWD_DeploymentResults.log" of folder "SWDDeployData" of folder "__Global" of data folder of client}"
parameter "targetLength" = "200"
if {windows of operating system}
waithidden cmd.exe /C echo %DATE% %TIME% >> "{parameter "logFolder"}\{parameter "logFile"}"
waithidden cmd.exe /C echo Action ID: {id of active action} >> "{parameter "logFolder"}\{parameter "logFile"}"
delete prometheus.ps1
delete __createfile
createfile until _EOF_
$truncatedContent = Get-Content "{parameter "logPath"}" -tail {parameter "targetLength"}
Remove-Item -Path "{parameter "logPath"}"
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines("{parameter "logPath"}", $truncatedContent, $Utf8NoBomEncoding)
#https://stackoverflow.com/a/5596984/5458134
Copy-Item "SWD_DeploymentResults.log" -Destination "{parameter "logPath"}"
Remove-Item -Path "SWD_DeploymentResults.log"
_EOF_
copy "__createfile" "prometheus.ps1"
waithidden powershell.exe -executionpolicy bypass -File "prometheus.ps1"
parameter "error" = "{exit code of action}"
waithidden cmd.exe /C echo Log truncated to {parameter "targetLength"} lines >> "{parameter "logFolder"}\{parameter "logFile"}"
waithidden cmd.exe /C echo Return Code: {parameter "error"} >> "{parameter "logFolder"}\{parameter "logFile"}"
waithidden cmd.exe /C echo. >> "{parameter "logFolder"}\{parameter "logFile"}"
delete "prometheus.ps1"
else
wait sh -c "echo '' >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"
wait sh -c "echo $(date +%Y_%m_%d' '%T) >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"
wait sh -c "echo Action ID: {id of active action} >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"
delete prometheus.sh
delete __createfile
createfile until _EOF_
#!/bin/sh
tail -n {parameter "targetLength"} "{parameter "logPath"}" > SWD_DeploymentResults.log
rm -rf "{parameter "logPath"}"
mv -f SWD_DeploymentResults.log "{parameter "logPath"}"
rm -rf SWD_DeploymentResults.log
_EOF_
copy "__createfile" "prometheus.sh"
wait chmod +x "prometheus.sh"
wait /bin/sh "prometheus.sh"
parameter "error" = "{exit code of action}"
wait sh -c "echo Log truncated to {parameter "targetLength"} lines >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"
wait sh -c "echo Return Code: {parameter "error"} >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"
delete "prometheus.sh"
endif
if {parameter "error" != "0"}
exit {parameter "error"}
endif
exit {parameter "error"}
This action will be considered successful when the applicability relevance evaluates to false.
Sharing
Social Media: |