-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfd-progress
More file actions
executable file
·55 lines (48 loc) · 1.03 KB
/
fd-progress
File metadata and controls
executable file
·55 lines (48 loc) · 1.03 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
#!/bin/bash
USAGE="$0 PID FD
A progress bar for a running process's position through a file.
The file must have a known size.
Env vars:
INTERVAL: Modify the refresh interval.
BANNER: Alternate program for percentage display (default 'banner')
"
if [ "$#" -lt 1 ]; then
echo "USAGE: $USAGE"
exit 1
fi
INTERVAL=${INTERVAL:-0.5}
BANNER=${BANNER:-banner}
PID="$1"
FD="$2"
while sleep "$INTERVAL"; do
if ! [ -d "/proc/$PID" ]; then
clear
echo "Process complete."
exit 1
fi
file="$(readlink "/proc/$PID/fd/$FD")"
if [ ! "$file" ]; then
clear
echo "File closed."
exit 1
fi
if [ "$file" != "$oldfile" ]; then
if [ -b "$file" ]; then
totalsize="$(blockdev --getsize64 "$file")"
elif [ -f "$file" ]; then
totalsize="$(stat -c %s "$file")"
else
clear
echo "Could not determine size of file: $file"
exit 1
fi
fi
oldfile="$file"
position="$(grep pos "/proc/$PID/fdinfo/$FD"| cut -f2)"
complete=$(python -c "print '%.2f' % ($position * 100. / $totalsize)")
clear
echo
echo "$file"
echo
$BANNER "$complete%"
done