From f6d7c3fdbecbcb880c0c02fdffefa1f467c46b03 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Thu, 7 May 2026 14:18:23 +0800 Subject: Allow specifying file size via CLI. --- seed.sh | 58 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 23 deletions(-) (limited to 'seed.sh') diff --git a/seed.sh b/seed.sh index bdfe71e..04412cf 100755 --- a/seed.sh +++ b/seed.sh @@ -1,36 +1,48 @@ #!/bin/ksh -# Accept directory count as an argument, default to 500 -TOTAL=${1:-500} +# 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" -CONTENT_SIZE=8000 - # 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 +# 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." -- cgit v1.2.3