Skip to content

Instantly share code, notes, and snippets.

@nicdoye
Created September 16, 2013 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicdoye/6579975 to your computer and use it in GitHub Desktop.
Save nicdoye/6579975 to your computer and use it in GitHub Desktop.
Gradually (nearly) fill a disk. Using it to test monit rules. Obviously on a real box, with other users, the disk could fill up. Caveat user.
#!/bin/bash
mountpoint=/tmp
sleeper=240
# percentage of disk used
function percentage { df $1 | tail -1 | awk '{print $4}' | tr -d % ; }
# Where we'll write
tempdir=$(mktemp -d --tmpdir=${mountpoint})
# Total disk in kB (Solaris needs the -k)
totalsize=$(df -k ${mountpoint}| tail -1 | awk '{print $1}')
# (roughly) 5% of the disk
writesize=$((${totalsize} / 20))
pct=$(percentage /tmp)
while [ ${pct} -lt 95 ]
do
# Create a file (roughly) 5% of the disk size
dd if=/dev/zero of=$(mktemp --tmpdir=${tempdir}) bs=${writesize}K count=1 &>> /dev/null
pct=$(percentage /tmp)
sleep ${sleeper}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment