I am attempting to create a cronjob that will run depending on the output of disk usage for a specific folder. In my test environment, I have a folder called "Test" that is 4.0 Kilobytes. I am querying its size with:
du -csh /home/<username>/Test | grep total | cut -f1 | tr -d 'K'
The output is assigned to a variable called DISK_SPACE and leaves me with 4.0
. I cannot figure out how to convert 4.0 to an integer in order to satisfy the following:
if [ $DISK_SPACE -gt 3.0 ]
then
rm -rf /home/<username>/Test/*.*
else
echo $DISK_SPACE "is less than 3.0K and as a result the contents of the folder will NOT be deleted."
My full bash file looks like the below:
#!/bin/bash
DISK_SPACE=$(du -csh /home/<username>/Test | grep total | cut -f1 | tr -d 'K')
echo $DISK_SPACE
if [ $DISK_SPACE -gt 3.0 ]
then
rm -rf /home/<username>Test/*.*
else
echo $DISK_SPACE "is less than 3.0K and as a result the contents of the folder will NOT be deleted."
fi
The error I receive after running this is:
4.0: integer expression expected