Following script will use netcat tool to send report emails from an ESXi server. For those who don't know about netcat tool according to wikipedia:-
Netcat (often abbreviated to nc) is a computer networking utility for reading from and writing to network connections using TCP or UDP. Netcat is designed to be a dependable back-end that can be used directly or easily driven by other programs and scripts.
Now create a file mail.sh and add following lines to it:-
{
sleep 5;
echo 'HELO smtp.something.net';
sleep 3;
echo 'MAIL FROM:<root@somthing.net>';
sleep 3;
echo 'RCPT TO: <admin@somthing.net>';
sleep 3;
echo 'DATA';
sleep 3;
echo 'Subject: Esxi RAID Status';
OUTPUT="$(./opt/hp/hpssacli/bin/hpssacli controller all show config)"
sleep 5;
echo "${OUTPUT}";
echo '.';
} | nc smtp_ip 25
Netcat (often abbreviated to nc) is a computer networking utility for reading from and writing to network connections using TCP or UDP. Netcat is designed to be a dependable back-end that can be used directly or easily driven by other programs and scripts.
Now create a file mail.sh and add following lines to it:-
{
sleep 5;
echo 'HELO smtp.something.net';
sleep 3;
echo 'MAIL FROM:<root@somthing.net>';
sleep 3;
echo 'RCPT TO: <admin@somthing.net>';
sleep 3;
echo 'DATA';
sleep 3;
echo 'Subject: Esxi RAID Status';
OUTPUT="$(./opt/hp/hpssacli/bin/hpssacli controller all show config)"
sleep 5;
echo "${OUTPUT}";
echo '.';
} | nc smtp_ip 25
This script will send RAID status of ESXi host to admin@somthing.net as per set cron. Modify smtp address ,RCP TO and MAIL FROM variable as your need and include desired command inside OUTPUT variable.
Don't forget to add execute permission
# chmod 755 mail.sh
Test Your script and you should get results something like this:-
Don't forget to add execute permission
# chmod 755 mail.sh
Test Your script and you should get results something like this:-
Check your inbox and you'll results of OUTPUT variable command.
No comments:
Post a Comment