sanjaysikdar.dev

Blog

HomeAboutTools
Sanjay Sikdar

Sanjay Sikdar

Software developer who enjoys developing software, solving challenges, and programming.

GithubLinkedInMain SiteSitemapRSS

© 2026 All rights reserved. Sanjay Sikdar

tutorialprogrammingtag-web-de

Shell script to get notification from the server

Sanjay Sikdar

Sanjay Sikdar

·Dec 27, 2023·1 min read

Installing Requirements

https://pypi.org/project/py-simple-email/

python
pip install py-simple-email

Creating the shell in python

bash
sudo nano /usr/local/bin/notify
python
#!/usr/bin/python3
from py_simple_email import Email
from datetime import datetime 
datetime_now = datetime.now()
 
email = Email( 
    EMAIL_HOST = 'email-smtp.ap-south-1.amazonaws.com', 
    EMAIL_HOST_USER = 'XXXXXXXXXXXXXXXXXXXXXX', 
    EMAIL_HOST_PASSWORD = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 
    EMAIL_PORT= 587,
    EMAIL_USE_TLS = True,
    DEFAULT_FROM_EMAIL = 'Sanjay Sikdar <hello@sanjaysikdar.dev>',
)
 
server_name = 'dev server'
domain = 'https://prod.sanjaysikdar.dev/'
ip = '128.128.128.128'
 
 
message = """\
Action Date & Time: {time}
Domain: {domain} ({ip})
 
""".format(time=datetime_now, domain=domain, ip=ip)
 
emails = ['hello@sanjaysikdar.dev', 'test@example.com']
for email_address in emails:
    email.send(
        to_email=email_address,
        subject=f'{server_name} performed some action',
        msg=message,
    )
bash
sudo chmod +x /usr/local/bin/notify

Now you can type notify anywhere in your terminal - server notifications will send to the selected emails.

Sanjay Sikdar

Written by Sanjay Sikdar

Software developer who enjoys developing software, solving challenges, and programming.