Monday, July 20, 2020

COVID-19 Email Notification

 


So out of nowhere, sitting home, working remotely may bother most of the people. Until my system is being repaired, I thought  of  doing something  else with Bash. I assume there are a lot of ways by which one can amuse oneself and can get updates about Covid19 infections statistics across the world/nation however, I  have created a little bash script that can automate this process and can be scheduled as a cron job in Linux to get the same update over an email, voila! 

Here is the script to be used.

============================================================================

#!/bin/bash


#Condition to check if the downloaded file is recent or not.
[ "$(stat -c %y /home/kapil/corona 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] &&
        curl -s https://corona-stats.online/ | sed  's/\x1b\[[0-9;]*m//g' > /home/kapil/corona

recpts="xyz124@gmail.com"
emailmsg=`grep -i "india" corona | sed "s/│/;/g ; s/║//g ; s/\s*//g" | awk -F';' '{print $2" Total case:"$3,"Total Deaths:"$5,"Recovered:"$7}'`

echo "An email  is being sent!!"
echo ""

sendemail -t $recpts -f abc124@hotmail.com -u "Automated Covid19 Update - India" -s smtp.live.com:587 -xu abc124@hotmail.com -xp Password@123 -o tls=yes -m "

Hi There,

This is just an automated email about Covid19. The following is the current update for India.

$emailmsg


Regards,

Script Admin
"
echo ""

#Downloaded file will get deleted.
rm /home/kapil/corona

============================================================================

Change following  as per your information  and the directory of your own choice for the update to be downloaded.

-t: To email
-f: From email
-xu: From email
-xp: From email password
-s: SMTP server (I am using Microsoft's live SMTP server, but we can find others on the internet.)
/home/kapil/corona: (Downloaded Covid19 stats file by script)

Required libraries for this script to be installed in Ubuntu or as per your distro. 

sudo apt-get install libnet-ssleay-perl
sudo apt-get install libcrypt-ssleay-perl

sudo apt-get install libio-socket-ssl-perl


Required email package to be installed.

sudo apt-get install sendemail 



Sample received email:


-----------------------------------------------------------------------------------------------------------------------------



-----------------------------------------------------------------------------------------------------------------------------

Save it in the crontab file in your Linux system and append the following  line in crontab file using following command. Here you go, your personal updates will be on your email as per scheduled mentioned.


crontab -e

#select your default text editor


# m h  dom mon dow   command


30 08 * * * * ./home/kapil/covidscript.sh


Save the script as covidscript.sh under your home directory as instructed above and modify crontab like this. Now every day in morning 08:30 you will get your email (Modify it as per your wish).


You may modify the script as per other requirements as well and it will  do the job for you.


Suggestions and improvements are welcomed. 


Thanks.  





Link to Page - Script





No comments:

Post a Comment

vSphere Series

vSphere Network Performance Troubleshooting - Part III

As I stated in my last post about utilizing the net-stats and vsish (vmkernel sys info shell) to gather useful network related information...