-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec.bat
31 lines (30 loc) · 1.48 KB
/
exec.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@echo off
call "%~dp0../env_vars.bat"
setlocal EnableDelayedExpansion
set "script=%~dp0mail_script.ps1"
(
java -cp "%~dp0zendesk-validate.jar;%lib%\*;" Main
if !ERRORLEVEL! NEQ 0 call :email
) >> "%~dp0log.txt" 2>&1
exit
:email
(
echo Send-MailMessage -From "!pbi_email!" -To "!error_email!".Split^(";"^) -Subject "Zendesk Validation Failure" -Body "This is an automated alert. The script which validates Zendesk job numbers against Quickbooks has encountered an error. See the log file for more details." -SmtpServer "smtp-mail.outlook.com" -Port 587 -UseSsl -Credential ^(New-Object PSCredential^("!pbi_email!", ^(ConvertTo-SecureString "!pbi_password!" -AsPlainText -Force^)^)^)
echo if ^( $? ^){ exit 0 }else{ exit 1 }
)>"%script%"
PowerShell -ExecutionPolicy Bypass -NoLogo -NonInteractive -File "%script%"
if %ErrorLevel% NEQ 0 (
echo [!date! - !time!] Failed to send email notification with 2 attempts left.>>"%~dp0log.txt"
timeout /t 5 /nobreak >nul
PowerShell -ExecutionPolicy Bypass -NoLogo -NonInteractive -File "%script%"
if !ErrorLevel! NEQ 0 (
echo [!date! - !time!] Failed to send email notification with 1 attempt left.>>"%~dp0log.txt"
timeout /t 5 /nobreak >nul
PowerShell -ExecutionPolicy Bypass -NoLogo -NonInteractive -File "%script%"
if !ErrorLevel! NEQ 0 (
echo [!date! - !time!] Failed to send email notification with 0 attempts left.>>"%~dp0log.txt"
)
)
)
if exist "%script%" del /F "%script%" >nul
exit /b 0