title: Alert if file grows more than a certain size in 5 minutes
body: <p>I'm trying to write a script to check how much a file has grown in the last 5 minutes, and write out to a log if it grows more than 20MB in that time.</p>
  
  <p>So far I've managed to write this;</p>
  
  <pre><code>output="$HOME/log/logsize.output"                       # This file is where the values are written to before being compared
  currentsize=$(stat '-c%s' "$HOME/log/input.log")        # This is the current size of the log file
  
      echo $currentsize &gt;&gt; $output
  
  oldsize=$(sed 'x;$!d' &lt; "$output")                      # Sets the previous reading as "oldsize" by pulling the second to last line of $output
  difference=$(("$currentsize" - "$oldsize"))             # This is the difference in size between the current and previous readings
  
  
  if $difference &gt; "1999999"                              # Checks the difference, if greater than 1999999 write an error.
      then
      echo "Warning! Log File has exceeded the expected rate of growth. Please investigate." &gt; "$HOME/log/logalert.log"
  else
      echo "Log File is within expected parameters" &gt; "$HOME/log/logalert.log"
  fi
  </code></pre>
  
  <p>When I run this script this is the output I recieve;</p>
  
  <pre><code>line 23: "2910" - "2910": syntax error: operand expected (error token is ""2910" - "2910"")
  </code></pre>
  
  <p>Solved!</p>
  
  <p>Here's what I did in the end to get this working</p>
  
  <pre><code>#!/bin/bash
  #########################################################################
  # Author - Jack Arnold
  #
  # Last Updated: 20.02.18
  #########################################################################
  #
  # This script exists to periodically check the file size of a log file.
  # If this file has grown 20MB or more since the last loop of this script
  # it will write out an alert to ~/logs/logsize.log
  #
  #########################################################################
  
  
  # Variables for the script.
  
  output="$HOME/log/logsize.output"                       # This file is where the values are written to before being compared
  currentsize=$(stat '-c%s' "$HOME/log/input.log")        # This is the current size of the log file
  
      echo "$currentsize" &gt;&gt; "$output"
  
  oldsize=$(sed 'x;$!d' &lt; "$output")                      # Sets the previous reading as "oldsize" by pulling the second to last line of $output
  difference=$((currentsize - oldsize))                   # This is the difference in size between the current and previous readings
  
  
  if [[ $difference &gt; "1999999" ]]                        # Checks the difference, if greater than 1999999 write an error.
      then
      echo "Warning! Log File has exceeded the expected rate of growth. Please investigate." &gt; "$HOME/log/logalert.log"
  else
      echo "Log File is within expected parameters" &gt; "$HOME/log/logalert.log"
  fi
  </code></pre>