Shell Script to monitor the growth of files in a specific directory



Script:

#!/bin/bash

# Set the directory to monitor and the max file size
dir="/path/to/directory"
max_size=1048576 # in bytes

# Loop through all files in the directory
for file in $dir/*; do
  # Get the size of the current file
  size=$(stat -c%s "$file")

  # Check if the file size is greater than the max size
  if [ $size -gt $max_size ]; then
    # Send an alert
    echo "File $file has exceeded the maximum size of $max_size bytes." | mail -s "File Size Alert" support@funoracleapps.com
  fi
done





If you like please follow and comment