-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnotorious
executable file
·49 lines (42 loc) · 1.34 KB
/
notorious
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
#!/usr/bin/env bash
################################################################################
# notorious - scp for big quantities of small files. This script automates the
# process of tarring up a directory of small files, transferring them, and then
# untarring them on the other side. This can improve performance when
# transferring tons of tiny, tiny files.
#
# Version 1
# Matthew Malensek <[email protected]>
################################################################################
progress_size=25
print_usage() {
cat <<EOM
Usage: $(basename ${0}) source dest-host:dest-dir
EOM
}
progress() {
perc=$(awk "BEGIN { print int(${1} / ${2} * 100) } ")
bars=$(( perc / (100 / progress_size) ))
echo -ne '\r['
for (( i=0; i < ${progress_size}; ++i, --bars )); do
if [[ ${bars} -gt 0 ]]; then echo -n '='; else echo -n ' '; fi
done
echo -n "] ${1}/${2} (${perc}%) "
}
if [[ ${#} -ne 2 ]]; then
print_usage
exit 1
fi
source=${1}
read host dest <<< $(IFS=":"; echo ${2})
num_files=$(ls -1 "${source}" | wc -l)
num_finished=0
timer=0
tar -c ${source} | ssh -c arcfour "${host}" "tar -C '${dest}' -vxf -" 2>&1 | \
while read; do
(( ++num_finished ))
if [[ ${SECONDS} -gt ${timer} ]]; then
timer=${SECONDS}
progress ${num_finished} ${num_files} &
fi
done