#!/bin/bash # v.0.0.0.1 # 21.4.2024 # scripts check directory size and if exceeds maximal size, notify via email to recipient # syntax: # check_dir_size [] # - path to check direcory. Directory must exists and be acessible # - whole number size in bytes # - email address to notify # - optional. Custom subject text. If not defined uses default. . ./qbashlib.sh default_subject="Warning notification - directory exceed maximal size." default_body="Directory '$1' exceed maximal size $2 bytes" body=$default_body subject=$default_subject # Zkontroluj, zda je zadán první argument argument_exists "$1" "" # Zkontroluj, zda existuje adresář s instalací Wordpressu if [ ! -d "$1" ]; then echo " directory '$1' not found or not accssible." exit 1 fi # Zkontroluj, zda je zadán druhý argument argument_exists "$2" "" # Zkontroluj, zda je zadán druhý argument jako číslo is_number $2 if [ $? -eq 0 ]; then echo " argument must whole number value." exit 1 fi # Zkontroluj, zda je zadán třetí argument is_email $3 if [ $? -eq 0 ]; then echo " argument '$3' is not valid email address." exit 1 fi # Zkontroluj, zda je zadán třetí argument if [ ! -z "$4" ]; then subject=$4 fi # porovnání velikosti adresáře proti maximální hodnotě dir_size=$(dir_get_size $1) if [ $dir_size -gt $2 ]; then # velikost přesáhls maximum -> notifikuj mail_send "$3" "$subject" "$body" fi