I am writing a shell script to rotate a log file based on size leveraging the logrotate.conf utility.
#!/bin/bash
FILENAME=/xyz/console.log
while :
do
FILESIZE=$(du -h "$FILENAME")
####FILESIZE=$(stat -c%s "$FILENAME")
if [[ $FILESIZE > 10K ]];
then
echo "$FILENAME is too large = $FILESIZE"
echo "$(date ) is here"
cd "/etc"
$sudo logrotate -f logrotate.conf
echo "$ Newer version of log file is created"
else
echo "Log limit is not reached"
fi
sleep 60s
done
exit 0
It is not printing else block ,even when the size is less than 10K. In all cases, it is executing the if block and rotating the logs even at 4.0K. Only when the log file is of zero bytes it is printing else part i.e.:
Log limit is not reached
statordu(without-h)? The problem is thatduwill bring the file name too, unless you usecut -f 1. The ideal is to get the value in bytes and compare.