batch script to send email notification once if any service goes down and sends mail once service is up

Hi Everyone,

Recently I came across an issue where oracle service on windows was getting stopped due to some reason. Since customer was not using any monitoring tool, it was very hard to track when the service was going down.

To mitigate the problem , I wrote a batch script which will monitor oracleservice and listener service on windows . The script will send a mail once notifying service has gone down and once service comes back it will send another notification on email with service is running message.

Save the following script in .bat format and schedule it as per your requirement in task scheduler.

@echo off

setlocal enabledelayedexpansion

set my_date=%date%

set my_time=%TIME%

set my_hours=%my_time:~0,2%

set my_minutes=%my_time:~3,2%

set my_seconds=%my_time:~6,2%

 

rem Configure email settings

 

set TO_EMAIL=soumya.das@email.com

set FROM_EMAIL=noreply@alerts.com

set SMTP_SERVER=smtp.gmail.com

set SMTP_PORT=587 

set SMTP_USER=noreply@alerts.com

set SMTP_PASSWORD=Password

set SUBJECT="Service Monitor Alert"

 

rem List of services to monitor (add more as needed)

set "SERVICES=OracleServiceORCL OracleOraDB19Home1TNSListener"

 

rem Create a temporary file to store service status

set STATUS_FILE=status.txt

 

rem Loop through the services and check their status using PowerShell

for %%s in (%SERVICES%) do (

    sc query "%%s" | find "STATE" | find "RUNNING" >nul

    if errorlevel 1 (

        echo %%s service is not running.

        if not exist !STATUS_FILE! (

            echo Sending email notification.

            powershell -command "Send-MailMessage -From '%FROM_EMAIL%' -To '%TO_EMAIL%' -Subject '%SUBJECT%' -Body 'The %%s service is not running.' -SmtpServer '%SMTP_SERVER%' -Port %SMTP_PORT% -UseSsl -Credential (New-Object PSCredential('%SMTP_USER%', (ConvertTo-SecureString '%SMTP_PASSWORD%' -AsPlainText -Force)))"

            rem Create the status file to indicate that an alert has been sent

            echo DOWN > !STATUS_FILE!

        )

    ) else (

        echo %%s service is running.

        if exist !STATUS_FILE! (

            echo Sending email notification.

            powershell -command "Send-MailMessage -From '%FROM_EMAIL%' -To '%TO_EMAIL%' -Subject 'Service Monitor Alert' -Body 'The %%s service is now running.' -SmtpServer '%SMTP_SERVER%' -Port %SMTP_PORT% -UseSsl -Credential (New-Object PSCredential('%SMTP_USER%', (ConvertTo-SecureString '%SMTP_PASSWORD%' -AsPlainText -Force)))"

            rem Delete the status file to indicate that the service is running

            del !STATUS_FILE!

        )

    )

)

 

endlocal


1 comment:

  1. Hello Everyone !

    If you're in searching of Legit & Fresh Fullz..
    You're at RIGHT PLACE

    Providing Fresh Spammed UPDATED 2023 Fullz with guarantee
    Stuff will be genuine & Legit (replace if found invalid)
    Many Countries Fullz Available
    USA|UK|CANADA|RU|AUS|FR|ASIA

    <-Feel Free To Contact Us & Enjoy->
    ---------------------------------
    ICQ> 752822040 | @killhacks
    Telegram> @killhacks | @leadsupplier
    Skype|WICKR> @peeterhacks
    Email> bigbull0334 @ onion mail . org
    WhatsApp> (On Demand)

    =============
    FULLZ LIST
    =============
    SSN DOB DL ADDRESS FULLZ
    SIN DOB ADDRESS FULLZ (CANADA)
    CC FULLZ WITH CVV & BILLING ADDRESS
    HIGH CREDIT SCORES PROS (700+ Credit)
    DL/ID SCAN FRONT & BACK WITH SELFIE & SSN (ALL USA STATES)
    BUSINESS EIN COMPANY FULLZ
    SPECIFIC FULLZ (GENDER|CITY|STATE|AGE)
    BULK FULLZ (USA|CANADA|UK)
    PUA|UI|KYC|TAX RETURN FILLING FULLZ
    CLONING DUMPS CARD WITH PIN (TRACK 101&202)
    YOUNG AGE FULLZ (2002 ABOVE)
    FULLZ WITH CURRENT EMPLOYEE & BANK DETAILS

    (USA)
    Name + SSN + Dob + DL|ID Number + Address + Phone + Email + Work Info + Bank Info
    claudia|gonzalez|567850156|10.04.1985|d3150237|335Dorisave|OXNARD|CA|93030|8056519095|8056519095|littleone0704@yahoo.com|cabrilloradiation|8056485133|VENTURACOUNTYCREDIT|144210|322283505

    (CANADA)
    NAME + ADDRESS + CITY + STATE + COUNTRY + DOB + SIN + PHONE + MMN + ZIPCODE
    KARINE BEAUDOIN|590 RUE PRINCIPALE|ST/THEOPHILE|QUEBEC|CA|1977/06/12|276-116-449|4182227484|LAMBERT|G0M 2A0

    CC Number + Expmm + Expyyyy + CVV + Name + Address + Country + SSN + DOB + Phone
    4610460213146269|07|24|914|Sydney Cutsail|9000 Tate Avenue|76244|Keller|Texas|United States|636-52-0685|04/06/1996|9034951145

    Many other stuff available regarding Fullz & Tools
    Payment Mode BTC|USDT|ETH (Preferable) or any Crypto payment accepted
    No sampling for CC's & DL|ID Scans
    Payment Upfront
    Stuff will be provided within few mins after payment proof
    Testing will be for bulk buyers only
    ***********************************************************************

    TOOLS|TUTORIALS|METHODS|CLONING|SCRIPTING|SCAM-PAGES

    All HACKING|SPAMMING|CARDING|SCRIPTING Tools are Available
    Including all tutorials & E-books
    Updated Loan Methods & Carding Methods

    TOOLS LIST
    -SMTP|RDP
    -SHELLS|C-PANELS
    -WEB MAILERS
    -BRUTES
    -MAILERS|SENDERS|BOMBERS
    -CC CHECKER|CC VALIDATOR
    -SMTP LINUX ROOT
    -SCAM PAGES|SCAM PAGE SCRIPTING
    -LOAN|ATM CARD METHODS
    -CLONING TUTORIALS
    -OFFICE365 LEADS|LOGINS|SMTPS

    Valid & Genuine Tools will be provided with guarantee
    Fresh Tools & Tutorials on demand with updates
    Hacking|Spamming|Carding Packages are available too
    No testing for Tools

    Here we're:
    -------------------------------------
    ICQ> 752822040 | @killhacks
    Telegram> @killhacks | @leadsupplier
    Skype|WICKR> @peeterhacks
    Email> bigbull0334 @ onion mail . org
    WhatsApp> (On Demand)

    Just Try Our Stuff
    It will Never Disappoint You Guy's
    Come & Join US to Make A GooD Money

    ReplyDelete