-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_data.sh
More file actions
executable file
·91 lines (79 loc) · 2.46 KB
/
random_data.sh
File metadata and controls
executable file
·91 lines (79 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# this file randomly creates and deletes files and directories on the
# production drive so our system can be tested over time.
# for each run of this script, a new file will be created containing a random
# number of bytes of random data. after this, there are four things that
# could happen:
# 1. this new file may be placed within a new directory
# 2. this new file may be placed within an existing directory
# 3. an existing file may be deleted
# 4. an existing directory may be deleted
# the "probabilities" of each of these options is defined at the beginning.
# USAGE: ./random_data.sh
DELDIR=7
DELFILE=6
PLACEDIR=4
NEWDIR=3
target_dir=/mnt/btrfs_project_drive/production/random
num=$RANDOM
numdirs=`find $target_dir/* -maxdepth 0 -type d | wc -l`
numfiles=`ls *.txt | wc -l`
# choose random directory within /random to delete, if we are deleting
if [ $numdirs -ne 0 ] && [ $(( $num % $DELDIR)) -eq 0 ] ;
then
randomdir=$((RANDOM % numdirs))
count=0
# iterate through subdirectories within target to find the one to delete
for dir in $target_dir/*/
do
dir=${dir%*/}
if [ $count -eq $randomdir ]
then
rm -rf $dir
break
fi
count=$((count+1))
done
numdirs=$((numdirs-1))
fi
# choose random file within /random to delete, if we are deleting
if [ $numfiles -ne 0 ] && [ $(( $num % $DELFILE)) -eq 0 ] ;
then
randomfile=$((RANDOM % numfiles))
count=0
# iterate through files within target to find the one to delete
for file in $target_dir/*.txt
do
if [ $count -eq $randomfile ]
then
rm $file
break
fi
count=$((count+1))
done
numfiles=$((numfiles-1))
fi
# create a new directory, if we are creating
if [ $(( $num % $NEWDIR)) -eq 0 ]
then
mkdir $target_dir/$num
target_dir=$target_dir/$num
# choose random directory within /random to place file into, if we are placing
elif [ $numdirs -ne 0 ] && [ $(( $num % $PLACEDIR)) -eq 0 ] ;
then
randomdir=$((RANDOM % numdirs))
count=0
# iterate through subdirectories to choose which one to place into
for dir in $target_dir/*/
do
dir=${dir%*/}
if [ $count -eq $randomdir ]
then
target_dir=$dir
break
fi
count=$((count+1))
done
fi
# create new file in target directory wtih random number of bytes
dd if=/dev/urandom bs=$((num/50)) count=4 > $target_dir/$num.txt