cat <<EOF > /etc/rotatescript/truncate.sh
FILENAME=/mnt/logs/filename
MAXSIZE=10000000000
FILESIZE=$(stat -c%s "$FILENAME")
if (( FILESIZE > MAXSIZE )); then
truncate -s 0 /mnt/logs/filename
else
echo “nope”
fi
As you can see, I am creating a shell script file using terminal. The problem here is that
FILESIZE=$(stat -c%s "$FILENAME")
The above value is saved inside FILESIZE variable when I execute the above code. So the value of FILESIZE is set as a constant.
Whereas, I want that whenever I actually run this shell script using the below command, linux dynamically picks the value for FILESIZE each time.
/etc/rotatescript/truncate.sh