#!/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 < $(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