-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfds-progress
More file actions
executable file
·62 lines (50 loc) · 1.16 KB
/
fds-progress
File metadata and controls
executable file
·62 lines (50 loc) · 1.16 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
#!/bin/bash
USAGE="$0 {PID:FD}
A progress bar for a running process's position through a file.
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}
first=true
while [ "$first" ] || sleep "$INTERVAL"; do
clear
flag=
first=
for arg in "$@"; do
pid=${arg%:*}
fd=${arg#*:}
if [ ! -d "/proc/$pid" ]; then
echo "$pid has terminated"
continue
fi
file="$(readlink -e "/proc/$pid/fd/$fd")"
if [ ! "$file" ]; then
echo "$pid has no readable fd $fd"
continue
fi
if [ -b "$file" ]; then
totalsize="$(blockdev --getsize64 "$file" 2>/dev/null)"
elif [ -f "$file" ]; then
totalsize="$(stat -c %s "$file" 2>/dev/null)"
else
echo "Cannot read size of $file"
continue
fi
position="$(grep pos "/proc/$pid/fdinfo/$fd"| cut -f2)"
complete=$((position * 100 / totalsize))
echo
echo
echo "$file"
echo
$BANNER "$complete%"
flag=true
done
[ ! "$flag" ] && break
done
echo "All readable processes complete, or no more files could have their size determined."