72 lines
2.1 KiB
Bash
72 lines
2.1 KiB
Bash
#!/bin/bash
|
|
if ! command -v vnstati >/dev/null; then echo "I require vnstati but it's not installed."; sudo apt install vnstati; else echo "vnstati OK"; fi;
|
|
if ! command -v sendmail >/dev/null; then echo "I require sendmail but it's not installed."; sudo apt install sendmail; else echo "sendmail OK"; fi;
|
|
if id -nG "$USER" | grep -qw "mail"; then echo "User in mail group"; else sudo usermod -aG mail $USER; fi
|
|
IFACE=$(ip -br l | awk '$1 !~ "lo|vir|vet|br|docker" { print $1}')
|
|
for i in $IFACE;do
|
|
vnstati -d 7 -i $i -o $i.png
|
|
vnstati -s -i $i -o $i.1.png
|
|
done
|
|
# path where files are stored for archival
|
|
SAVEPATH=$HOME
|
|
#mkdir -p $SAVEPATH
|
|
# declare the array with the images to mail, can be as many as you want.
|
|
#declare -A ATTS
|
|
ATTS=(*.png)
|
|
#for f in ${ATTS[@]}; do
|
|
# echo "Processing $f file...";
|
|
#done
|
|
|
|
for key in "${!ATTS[@]}"; do
|
|
# due to formatting of the base64 output in the command loop
|
|
# the file must be base64 encoded in a variable.
|
|
# here we encode the file, in the loop we get in it a var.
|
|
value=${ATTS[$key]};
|
|
/usr/bin/base64 "$SAVEPATH/$value" > $SAVEPATH/$value.base64;
|
|
done
|
|
|
|
/usr/sbin/sendmail -t <<EOT
|
|
TO: alfonso@vivancos.eu
|
|
FROM: $USER@$(hostname -A)
|
|
SUBJECT: $HOSTNAME traffic summary $(date +%c)
|
|
MIME-Version: 1.0
|
|
Content-Type: multipart/related;boundary="XYZ"
|
|
|
|
--XYZ
|
|
Content-Type: text/html; charset=ISO-8859-15
|
|
Content-Transfer-Encoding: 7bit
|
|
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
|
|
</head>
|
|
<body bgcolor="#ffffff" text="#000000">
|
|
$(for key in "${!ATTS[@]}"; do
|
|
value=${ATTS[$key]};
|
|
# echo "<h1>$value</h1>";
|
|
# echo "<h1>$key</h1>";
|
|
echo "<img src=\"cid:$value\"></br>";
|
|
done)
|
|
</body>
|
|
</html>
|
|
|
|
$(for key in "${!ATTS[@]}"; do
|
|
value=${ATTS[$key]};
|
|
ATT=$(cat $SAVEPATH/$value.base64);
|
|
echo "--XYZ"
|
|
echo "Content-Type: image/png;name=\"$value\""
|
|
echo "Content-Transfer-Encoding: base64"
|
|
echo "Content-ID: <$value>"
|
|
echo "Content-Disposition: inline; filename=\"$value\""
|
|
echo ""
|
|
echo "$ATT"
|
|
done)
|
|
--XYZ--
|
|
EOT
|
|
|
|
|
|
for key in "${!ATTS[@]}"; do
|
|
value=${ATTS[$key]};
|
|
rm $SAVEPATH/$value.base64;
|
|
rm $SAVEPATH/$value;
|
|
done |