Created
June 6, 2014 15:07
-
-
Save bonsaiviking/39b43214d26fb1247cfc to your computer and use it in GitHub Desktop.
Display progress reading/writing a file according to position information on the file descriptor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: progress.sh $(pgrep myprocess) $FD_NUMBER | |
# Find $FD_NUMBER by doing: ls -l /proc/$(pgrep myprocess)/fd/ | |
fd=/proc/$1/fd/$2 | |
fdinfo=/proc/$1/fdinfo/$2 | |
name=$(readlink $fd) | |
size=$(wc -c $fd | awk '{print $1}') | |
while [ -e $fd ]; do | |
progress=$(cat $fdinfo | grep ^pos | awk '{print $2}') | |
echo $((100*$progress / $size)) | |
sleep 1 | |
done | dialog --gauge "Progress reading $name" 7 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment