Python Tutorial: Write a Script to Monitor a Website, Send Alert Emails, and Reboot Servers

Share it with your friends Like

Thanks! Share it with your friends!


In this Python Programming Tutorial, we’re going to be looking at a real-world example of writing a script to monitor a website. If the website doesn’t return a successful response for any reason then we will send an email and reboot the web server. Let’s get started…

The code from this video (with added logging) can be found at:

Google Account Settings:

Requests Video –

Environment Variables (Windows) –
Environment Variables (Mac and Linux) –

Try/Except Video –

F-String Video –

Crontab Video –

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –



Corey Schafer says:

I put the code to this script in the description section of the video. For anyone who would like to see what some basic logging would look like for this script, I added some logging code to the script and commented it out for reference. I hope you all find these real-world examples helpful!

David Jones says:

I have a half finished app on my GitHub a bit like this, it monitors a list of sites with requests and sends and email for any that are down and it runs every min on AWS Lambda. I have another part that uses paramiko which will then ssh into the server of any site that is down to debug the issues. I didn't get any further than that the plan was/is for paramiko to run commands such as check the status of apache, RAM, disk space, mysql etc etc and run re-boot commands accordingly for any that are failing or send further alerts.

praveenraj sr says:

One of the best tutorial in the entire universe!

Andri Hidayat says:

I think that I will never unsubscribe your channel because You have a monster power sir, you can do great python programming and also CLI master on Linux. If I can make a request then I hope next time you make video about get how many user connecting to a network and then adjust the equal bandwidth for every hosts using iptables by using python power. Thank you.

Hamid S says:

Love your mini projects. These are awesome please keep posting

Alexey Bogomolov says:

Awesome tutorial! It helped me to become familiar with virtualenv development. Also I realized how to work with API of my VPS provider. Did my own server monitoring script with your guidance. Also realized I had to add local variables initialization to cron to get it to work. Looking forward to bring it further. Thanks!

Sheshank Shankar says:

Hey Corey, when will the Flask Heroku deployment video come? I am not very smart and I can't figure it out myself and with other videos. I learned Flask through your series, and I think I will be able to deploy my site if this deployment video comes. Thanks!

Moondra says:

Nice stuff! I have a lot of catching up to do =)

micheal hall says:

r.ok is a built in method that returns True if status is 200

Kobe Bryant says:

Hey Corey, since you're uploading general python episodes regurarly now, how about a guide to asyncio in python 3.7?
Also, I'm getting my first IT-payment this month thanks to You and You're gettng patronized!

Matin R says:

You have the best python tutorials Corey,
Thank you so much for the efforts you put into these videos.
Keep it up

Joseph M Orost says:

Thank you! Why didn’t you just put your script in an infinite loop and sleep for 10 mins each time around (with some more try blocks in case of sending email fails or the restart fails)?

Klint Krossa says:

try: except: else: ????

raghav atreya says:

Hello ,
Why you are using the node server? Does Django server is not good?

metalmasterlp says:

amazing videos, please keep it up. Best i've seen on YT so far

Arch Stampton says:

I particularly appreciated that you indicated why and how you gradually improved your script. Too many times, I find those complicated scripts on github and I wonder what were the steps to get to the final version.

Write a comment