Skip to content

Instantly share code, notes, and snippets.

@bonsaiviking
Created June 6, 2014 15:07
Show Gist options
  • Save bonsaiviking/39b43214d26fb1247cfc to your computer and use it in GitHub Desktop.
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.
#!/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