Could we help you? Please click the banners. We are young and desperately need the money
A customer needed to be informed about his servers storage capacities on a regular basis. The script we wrote is very much focused on customers use case. It's has not been created with a lot of flexibility in mind. Although it might help you create your own script based on this.
#!/bin/bash
set +v
set +x
## E-Mail settings
MAIL_SENDER="mail-sender-name" ##defines the user account which is used to send out e-mails. This particular user account does not need to have a shell assigned
MAIL_SUBJECT="LOCAL Server | EXTERNAL Server | Storage Information"
MAIL_RECIPIENTS="serveradmin@yourdomain.tld" ##send mail to multiple receipients by overgiving a space-seperated address list
MAIL_AGENT=`which mail`
## Get storage information from various systems
LOCAL_SERVER_STORAGE=($(df -h /dev/sda2))
EXTERNAL_SERVER_STORAGE=($(ssh admin@EXTERNAL_SERVER 'df -h /dev/sda3'))
declare -p LOCAL_SERVER_STORAGE &>/dev/null
declare -p EXTERNAL_SERVER_STORAGE &>/dev/null
## Get all OwnCloud user storage information and sort the directories according to their storage consumption in reverse order
OC_USR_STORAGE=( $(for i in $(find /home/ocdata -maxdepth 1 -type d |grep -E -i -v "(avatars|cache|\.locks)"); do du -smh "$i"; done |sort -hr) )
## Create mail body
MAIL_BODY="Please note the following storage information data taken on `date +%d.%B.%Y,%T`:"
MAIL_BODY="${MAIL_BODY}\n\n\n"
MAIL_BODY="${MAIL_BODY}--------------------- LOCAL_SERVER STORAGE INFORMATION ---------------------"
MAIL_BODY="${MAIL_BODY}\n\n"
MAIL_BODY="${MAIL_BODY}Storage Capacity:\t ${LOCAL_SERVER_STORAGE[8]}\n"
MAIL_BODY="${MAIL_BODY}Storage Used:\t\t ${LOCAL_SERVER_STORAGE[9]}\n"
MAIL_BODY="${MAIL_BODY}Storage Used (%):\t ${LOCAL_SERVER_STORAGE[11]}\n"
MAIL_BODY="${MAIL_BODY}Storage Free:\t\t ${LOCAL_SERVER_STORAGE[10]}\n"
MAIL_BODY="${MAIL_BODY}\n\n"
MAIL_BODY="${MAIL_BODY}\n\n"
MAIL_BODY="${MAIL_BODY}--------------------- EXTERNAL_SERVER STORAGE INFORMATION ---------------------------------"
MAIL_BODY="${MAIL_BODY}\n\n"
MAIL_BODY="${MAIL_BODY}Storage Capacity:\t ${EXTERNAL_SERVER_STORAGE[8]}\n"
MAIL_BODY="${MAIL_BODY}Storage Used:\t\t ${EXTERNAL_SERVER_STORAGE[9]}\n"
MAIL_BODY="${MAIL_BODY}Storage Used (%):\t ${EXTERNAL_SERVER_STORAGE[11]}\n"
MAIL_BODY="${MAIL_BODY}Storage Free:\t\t ${EXTERNAL_SERVER_STORAGE[10]}\n"
MAIL_BODY="${MAIL_BODY}\n\n"
MAIL_BODY="${MAIL_BODY}\n\n"
MAIL_BODY="${MAIL_BODY}--------------------- OWNCLOUD USER STORAGE INFORMATION ----------------------------"
MAIL_BODY="${MAIL_BODY}\n\n"
### List per-user OwnCloud storage information
OC_USR_STORAGE_LENGTH=${#OC_USR_STORAGE[@]}
for (( STORAGECOUNTER=0; STORAGECOUNTER<${OC_USR_STORAGE_LENGTH}; STORAGECOUNTER++ ));
do
case ${STORAGECOUNTER} in
0)
MAIL_BODY="${MAIL_BODY}${OC_USR_STORAGE[i]}\t\tTotal storage used in all userfolders\n\n"
MAIL_BODY="${MAIL_BODY}Size\t\tUser folder\n"
MAIL_BODY="${MAIL_BODY}------------------------------------\n"
STORAGECOUNTER=$(( STORAGECOUNTER + 1 ))
continue
;;
*)
### Strip the "/home/ocdata/" information from the usernames in order to present a cleaner overview (customer does not need to know the real path)
CURR_PATH=${OC_USR_STORAGE[STORAGECOUNTER+1]/\/home\/ocdata\//}
MAIL_BODY="${MAIL_BODY}${OC_USR_STORAGE[${STORAGECOUNTER}]}\t\t${CURR_PATH}\n"
STORAGECOUNTER=$(( STORAGECOUNTER + 1 ))
;;
esac
done
sudo -u ${MAIL_SENDER} echo -e ${MAIL_BODY} | sudo -u ${MAIL_SENDER} ${MAIL_AGENT} -s "${MAIL_SUBJECT}" ${MAIL_RECIPIENTS}