-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec.bat
33 lines (32 loc) · 1.62 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
32
33
@echo off
call "%~dp0../env_vars.bat"
setlocal EnableDelayedExpansion
set "script=%~dp0mail_script.ps1"
set "ret=0"
(
java -Djava.library.path="C:\Program Files (x86)\CLEARIFY\QQube Tool\SQL Anywhere 17\BIN64" -cp "%~dp0qqube-validate.jar;%lib%\*;C:\Program Files (x86)\CLEARIFY\QQube Tool\SQL Anywhere 17\Java\sajdbc4.jar" Main
set "ret=!ERRORLEVEL!"
) > "%~dp0log.txt" 2>&1
if "!ret!" NEQ "0" call :email
exit
:email
(
echo Send-MailMessage -From "!pbi_email!" -To "!error_email!".Split^(";"^) -Subject "QQube Validation" -Body "This is an automated alert. Status=%ret%. See the attached log file for more details." -Attachments "%~dp0log.txt" -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