#!/bin/ksh
# Accept directory count as an argument, default to 500
TOTAL=${1:-500}
# Define the base path relative to the script location
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
BASE_DIR="$SCRIPT_DIR/_site/log"
# Target size: 16000 bytes is ~15.6 KB
CONTENT_SIZE=16000
# Ensure the target directory exists
mkdir -p "$BASE_DIR"
for i in $(seq 1 $TOTAL); do
DIR="$BASE_DIR/site_$i"
mkdir -p "$DIR"
# Start the file structure
echo "
Site $i" > "$DIR/index.html"
# Generate random text using dd for byte-level precision
# We read 32KB of raw data to account for characters filtered out by tr,
# then use dd again to trim the result to exactly CONTENT_SIZE bytes.
dd if=/dev/urandom bs=32768 count=1 2>/dev/null | tr -dc 'a-zA-Z0-9 ' | dd bs=1 count=$CONTENT_SIZE 2>/dev/null >> "$DIR/index.html"
# Append keyword and close tags
echo " Searchable content here for keyword_$i.
" >> "$DIR/index.html"
# Print progress every 100 files
if [ $((i % 100)) -eq 0 ]; then
echo "Created $i files..."
fi
done
echo "Done! $TOTAL directories created in $BASE_DIR."