Count the size and send notification

Hello,

I want to do something simple,

I want to count the dir size (du -sh directoryname) and then check if
it is over 100GB.
If it is more than 100GB I want to send a notification , if it less than 100GB the script can just stop.

I know how to count with du -sh and how to send an email but I dont know how to compare with 100GB, any help?

thank you.

Hi,

don't use -h option, it show you in human readable

thank you for the tip pokerino,
but how do I say "if its more than $ then do this" ?

try and modify this:

pass a directory as argument.
adjust the max value when needed

to get the file size in number(GB)

stat -c %s infile | awk '{print $1/(1024**3)}'

The output from du -sk is in 1024 byte blocks.

100 Gb = (100 x 1024 x 1024 x 1024) bytes
Which is the same as (100 x 1024 x 1024) blocks of size 1024 bytes. i.e. 104857600 1024-byte blocks.

dir="directoryname"
blocks=$(du -sk "${dir}" | awk '{print $1')
if [ $blocks -gt 104857600 ]
then
       echo "Directory larger than 100 Mb: ${dir}"
fi

@pokerino Your units are incorrect.