-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbringg_script.sh
More file actions
executable file
·65 lines (50 loc) · 1.24 KB
/
Copy pathbringg_script.sh
File metadata and controls
executable file
·65 lines (50 loc) · 1.24 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
#!/bin/bash
# $1 is the email / user you want to notify
script=$(basename -- $0)
email=$1
dir_array=()
function send_email {
echo "$script has failed" | mail -s 'Oh no!' $email && echo "Email sent to $email"
}
function check_running {
if pidof -x $script -o $$ > /dev/null ; then
echo "Instance of script already running, exiting"
return 1
fi
}
function create_folders {
for i in {1..100} ; do
dir=$RANDOM$RANDOM
mkdir $dir && dir_array+=($dir)
done
}
function create_files {
for dir in ${dir_array[@]} ; do
for file in {1..100} ; do
prefix_array=(a b c)
size_array=(`seq 50 200 | sort -R`)
random_prefix=${prefix_array[$RANDOM % ${#prefix_array[@]}]}
random_size=${size_array[$RANDOM % ${#size_array[@]}]}
file_name=`echo -e "$random_prefix$RANDOM"`
cat /dev/urandom | tr -dc 'a-zA-Z0-9 ' | head -c "$random_size"k > $dir/$file_name
done
done
}
function remove_spaces {
for dir in ${dir_array[@]} ; do
find $dir -type f | xargs sed -i s/" "/""/g
done
}
function create_md5 {
for dir in ${dir_array[@]} ; do
for file in `ls $dir` ; do
md5sum $dir/$file > $dir/$file.md5
done
done
}
check_running \
&& create_folders \
&& create_files \
&& remove_spaces \
&& create_md5 \
|| send_email