| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #!/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_dir> <maximum_size> <recipient> [<custom_subject>]
- # <path_to_dir> - path to check direcory. Directory must exists and be acessible
- # <maximum_size> - whole number size in bytes
- # <recipient> - email address to notify
- # <custom_subject> - 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" "<path_to_dir>"
- # Zkontroluj, zda existuje adresář s instalací Wordpressu
- if [ ! -d "$1" ]; then
- echo "<path_to_dir> directory '$1' not found or not accssible."
- exit 1
- fi
- # Zkontroluj, zda je zadán druhý argument
- argument_exists "$2" "<maximum_size>"
- # Zkontroluj, zda je zadán druhý argument jako číslo
- is_number $2
- if [ $? -eq 0 ]; then
- echo "<maximum_size> argument must whole number value."
- exit 1
- fi
- # Zkontroluj, zda je zadán třetí argument
- is_email $3
- if [ $? -eq 0 ]; then
- echo "<recipient> 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
|