From f22163eefbda98a73480d7f7f2c14e95bc162f82 Mon Sep 17 00:00:00 2001 From: borekon Date: Tue, 14 Mar 2023 11:27:15 +0000 Subject: [PATCH] =?UTF-8?q?A=C3=B1adir=20'vnstati.sh'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnstati.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 vnstati.sh diff --git a/vnstati.sh b/vnstati.sh new file mode 100644 index 0000000..b9b93b1 --- /dev/null +++ b/vnstati.sh @@ -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 < + + + + +$(for key in "${!ATTS[@]}"; do + value=${ATTS[$key]}; +# echo "

$value

"; +# echo "

$key

"; + echo "
"; +done) + + + +$(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 \ No newline at end of file