Skip to content

Instantly share code, notes, and snippets.

@ephrin
Last active January 24, 2024 16:13
Show Gist options
  • Save ephrin/787ec451b4fcaf9008a9771f517a38e5 to your computer and use it in GitHub Desktop.
Save ephrin/787ec451b4fcaf9008a9771f517a38e5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Directory to fill with files
DIR=$1
# Threshold for free space in KB
THRESHOLD=${2:-104857} # Default is 100MB
# Size of each file in KB
FILESIZE=5120 # 5MB
# Check if directory exists
if [ ! -d "$DIR" ]; then
echo "Directory $DIR does not exist."
exit 1
fi
# Function to get free disk space
get_free_space() {
df "$DIR" | tail -1 | awk '{print $4}'
}
# Create files until free space threshold is reached
while true; do
FREE_SPACE=$(get_free_space)
if (( FREE_SPACE < THRESHOLD )); then
echo "Free space has reached the threshold. Stopping."
break
fi
# Generate a random filename
FILENAME=$(mktemp -u XXXXXX)
# Create a file with random bytes
dd if=/dev/urandom of="$DIR/$FILENAME" bs=1024 count=$FILESIZE >/dev/null 2>&1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment