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





Saturday, July 18, 2020

vSphere Network Performance Troubleshooting - Part II


Previous post was about collecting detail of sent-received packets, dropped packets, missed errors at each vmnic connected. 

Now we can dig further and can get following information.

Ø  World-ID of running virtual machines.

Ø  Ports associated with the given world-ID of virtual machines.

Ø  Retrieve the switch statistics of packet transmitted and received for ports.

Ø  Received and transmitted packet drop for ports.

Ø  Retrieves filter stats and information for ports.

Ø  Switch associated with the port and detail of uplink assigned.

All of these information can be retrieved using following bash script:


echo VMs with world id : ; esxcli network vm list;echo "";for i in $(esxcli network vm list | awk '{print $1}' | grep -viE "world|--------");do echo "For this world id :$i following are the ports associated :==========" ;esxcli network vm port list -w $i | grep -iw "port id" | grep -vi "uplink" | sed 's/   //' | awk '{print $3}';for j in $(esxcli network vm port list -w $i| grep -iw "port id" | grep -vi "uplink" | sed 's/   //' | awk '{print $3}');do echo "";esxcli network port stats get -p $j;echo Port filter stats for $j:;esxcli network port filter stats get -p $j;done;echo "";esxcli network vm port list -w $i | grep -iEw "port id|vswitch|team uplink|mac address";echo "==========================";done


Here we are able to extract statistical information about the underlying network associated to running virtual machines and vmnics which then were used to retrieve ports stats and filter information about it.

Similarly we can get network port stats for all associated client or virtual machines using net-stats and Vmkernel Sys Info Shell (vsish) utility, I shall be creating similar script that can automate the process of retrieving additional network statistics using these utilities in my next post of this series.


If you find it helpful, please be social and share it in your circle. Please comment your suggestion and improvement to be catered in future posts.


Link to Page - vSphere



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...