Añadir 'vnstati.sh'

This commit is contained in:
borekon 2023-03-14 11:27:15 +00:00
parent 7a5b4e9aa1
commit f22163eefb

72
vnstati.sh Normal file
View File

@ -0,0 +1,72 @@
#!/bin/bash
if ! command -v vnstati >/dev/null; then echo "I require vnstati but it's not installed."; apt install vnstati; else echo "vnstati OK"; fi;
if ! command -v sendmail >/dev/null; then echo "I require sendmial but it's not installed."; apt install sendmail; else echo "sendmail OK"; 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: alfonso@cayuela.eu
BCC: vivancos@gmail.com
SUBJECT: Cayuela 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