-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec.bat
34 lines (33 loc) · 1.51 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
34
@echo off
call "%~dp0../env_vars.bat"
setlocal EnableDelayedExpansion
set "script=%~dp0mail_script.ps1"
(
"C:\Program Files\Python312\python.exe" "%~dp0__init__.py"
if !ERRORLEVEL! NEQ 0 (
echo An error was encountered.
call :email
)
) >> "%~dp0log.txt" 2>&1
exit
:email
(
echo Send-MailMessage -From "!pbi_email!" -To "!error_email!".Split^(";"^) -Subject "Cradlepoint API Failure" -Body "This is an automated alert. The script which populates the cradlepoint database tables has failed. 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