#!/bin/ksh # Usage: ./seed.sh size filecount # Example: ./seed.sh 4.1 500 INPUT_SIZE=$1 TOTAL=$2 if [[ -z "$INPUT_SIZE" || -z "$TOTAL" ]]; then echo "Usage: $0 " exit 1 fi # Define the base path relative to the script location SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) BASE_DIR="$SCRIPT_DIR/_site/log" # Ensure the target directory exists mkdir -p "$BASE_DIR" # Convert KB to raw bytes for dd precision CONTENT_SIZE=$(awk -v kb="$INPUT_SIZE" 'BEGIN { printf "%.0f", kb * 1024 }') echo "Generating $TOTAL directories in $BASE_DIR (File size: $INPUT_SIZE KB)..." i=1 while [[ $i -le $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 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 (( i += 1 )) done echo "Done! $TOTAL directories created in $BASE_DIR."