Very new to bash as you will see in code below.
I want to get the file size in bytes of a file, compare that to a fixed value and send an email if the latter is too small.
Code:
#!/bin/bash
f=$(find /var/lib/xxxxxx/backups/xxxxxxxxDB*.gz -ctime 0 -print -exec ls -l {} \; | awk '{print $5}')
if [$f -lt 60000000000] ; then
echo "hello";
fi
The output of the command above is 18607414901
bytes, i.e. 18gb.
What I want is to execute command if that is less than 60gb. The echo
command is used just to test that.
./backupsql.sh: line 4: [: missing `]'
find
command (man find
)? it likely has an option to identify files that are smaller than a given size directly. – steeldriver May 19 '17 at 15:08find ... -printf "%s\n"
(no need for externalls
). Also, as steeldriver hinted, even POSIX find has-size
to match based on the file size. – ilkkachu May 19 '17 at 21:59