diff options
Diffstat (limited to 'seed.sh')
| -rwxr-xr-x | seed.sh | 58 |
1 files changed, 35 insertions, 23 deletions
@@ -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 <size_kb> <file_count>" + 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 "<html><head><title>Site $i</title></head><body><main><p>" > "$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. </p></main></body></html>" >> "$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 "<html><head><title>Site $i</title></head><body><main><p>" > "$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. </p></main></body></html>" >> "$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." |
