Advertisement
fant0men

zero_test.sh

Nov 11th, 2020 (edited)
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.50 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This script is meant to test a drive to see if it's okay or not, by
  4. # writing 100M files (filled with zeroes) until the space runs out.
  5.  
  6. set -eo pipefail
  7.  
  8. if [[ ! -d $1 ]]; then
  9.     echo -e "Usage: $(basename "$0") [dir]\n"
  10.     exit
  11. fi
  12.  
  13. dir=$(readlink -f "$1")
  14. out_dir="${dir}/zero-${RANDOM}"
  15.  
  16. mkdir -p "$out_dir"
  17.  
  18. n='0'
  19.  
  20. while [[ $? -eq 0 ]]; do
  21.     n=$(( n + 1 ))
  22.     of="${out_dir}/zero_${n}"
  23.  
  24.     if [[ ! -f $of ]]; then
  25.         dd if=/dev/urandom of="$of" bs=1M count=100
  26.     fi
  27. done
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement