-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcp-progress
More file actions
executable file
·64 lines (55 loc) · 1.34 KB
/
cp-progress
File metadata and controls
executable file
·64 lines (55 loc) · 1.34 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
USAGE="$0 (PID|{ARGS})
A progress bar for a running cp process.
The process may be given by PID or by any number of ARGS as understood by pgrep(1).
'pgrep ARGS' should match the process name (including arguments) uniquely.
When copying multiple files, each is treated as a seperate copy,
ie. only progress through the current file is given.
Env vars:
INTERVAL: Modify the refresh interval.
BANNER: Alternate program for percentage display (default 'banner')
"
if [ "$#" -lt 1 ]; then
echo "USAGE: $0 [--dir] PID"
exit 1
fi
INTERVAL=${INTERVAL:-0.5}
BANNER=${BANNER:-banner}
if [ "$1" == "--dir" ]; then
FROM_FD=4
TO_FD=5
shift 1
else
FROM_FD=3
TO_FD=4
fi
if grep -Eq "^ *[0-9]+ *$" <<<"$1"; then
# Is numeric
PID="$1"
else
PID="$(pgrep "$@")"
if [ "$(wc -l <<<"$PID")" -ne 1 ]; then
echo "Bad process specification."
exit 1
fi
fi
while sleep "$INTERVAL"; do
if ! [ -d "/proc/$PID" ]; then
clear
echo "Process complete."
exit 0
fi
fromfile="$(readlink "/proc/$1/fd/$FROM_FD")"
if [ ! "$fromfile" ]; then continue; fi
if [ "$fromfile" != "$oldfile" ]; then
totalsize="$(stat -c %s "$fromfile")"
fi
oldfile="$fromfile"
position="$(grep pos "/proc/$1/fdinfo/$TO_FD"| cut -f2)"
complete=$(python3 -c "print('%.2f' % ($position * 100. / $totalsize))")
clear
echo
echo "Copying $fromfile"
echo
$BANNER "$complete%"
done