Hi folks,
I've written a script that fills a disk with a large file and checks the md5 each time. I'm writing a 500GB iso (ubuntu server iso incidentally) over and over coming up with a unique name using `date +%s`. I'm using it to check for disk corruption. I want to run it for several days/weeks.
The problem is, i don't know how to adjust my script to clear the hard drive once it's full and start over. I've managed to get some logic in to that it'll stop when there's about 1gb of free space left (to avoid the script from erroring). Once the while loops ends i want it to delete the files it wrote (there's no critical data on the array so an "rm -rf filldisk*" will be fine) and then start over writting files.
Essentially, i want the script to run forever unless stopped by hand. In the DOS batch world (*shudder*) i'd use a simple goto. After some searching, a goto is frowned upon (and doesn't work in bash). I'm hoping someone can give me some insight.
Here's the code:
Code:
#!/bin/bash
# filldisk.sh
# This script will take a file and copy it to a specified location, over and over until the disk is full
# each copy will be MD5 checked to ensure integrity.
#
# It is recommended that you setup a RAMDisk, copy a file there and use that as the source.
#
if [ $# -lt 4 ]
then
echo "";
echo "filldisk.sh"
echo "This script fills the disk. You need to pass commands to it."
echo "filldisk.sh <sourcefile_fullpath> <destination_fullpath> <mountpoint> <your_email_address>"
echo "";
echo "example:";
echo "filldisk.sh /mnt/ramdisk/bigfile.iso /bigarray /mnt/bigarray you@domain.com"
echo "";
echo "A error log is dumped to <destination_fullpath>\filldisk_errorlog.log"
echo "";
exit 1
fi
source="$1"
dest="$2"
mountpoint="$3"
email="$4"
drop_cache=`cat /proc/sys/vm/drop_caches`
chksum=`md5sum $1 | awk '{print $1}'`
# Check for source file
if [ ! -e $source ]
then
echo "";
echo "ERROR!! Source file not found"
echo "";
exit 1
fi
# Check for destination path
if [ ! -e $dest ]
then
echo "";
echo "ERROR!! Destination not found"
echo "";
exit 1
fi
# Check for mount
if [ ! -e $mountpoint ]
then
echo "";
echo "ERROR!! Mount point not found"
echo "";
exit 1
fi
# Kill the drop_cache
sync
echo 3 > /proc/sys/vm/drop_caches
# Start copying loop...
while [ `df | grep $3 | awk '{print $4}'` -gt 1000000 ]; do
now=`date +%s`
# echo "$dest/filldisk-$now"
cp $source $dest/filldisk-$now
md5sum $dest/filldisk-$now > $dest/filldisk-$now.md5
dest_chksum=`cat $dest/filldisk-$now.md5 | awk '{print $1}'`
# Compare Checksum of the destination file and report an error if there's a mismatch
if [ $chksum != "$dest_chksum" ]
then
echo "CHECKSUM ERROR ON FILE filldisk-$now!"
echo "CHECKSUM ERROR ON FILE filldisk-$now!" > $dest/filldisk_failures.log
sendmail -f `hostname`@domain.com $email < $dest/filldisk_failures.log
fi
echo Copy complete, checksum calculated. Remaining free diskspace is `df -h | grep $3 | awk '{print $4}'`
done
# Revert the drop_cache back to old setting
echo $drop_cache > /proc/sys/vm/drop_caches
# done
echo "All done"
As you can see it stops once the disk is full. It works well, but only runs for about 10 hours on a 1.5TB array i'm testing against. I think i need a "while while" loop or something, but i'm having trouble wrapping my brain around it. Thanks for looking.