Last active
April 13, 2023 14:41
-
-
Save unhammer/b0ab6a6aa8e1eeaf236b to your computer and use it in GitHub Desktop.
Show progress of some command you forgot to pipe through pv
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 | |
### Save as "/usr/local/bin/progress" and chmod +x, then: | |
# | |
# $ progress ~/huge-file.tar.bz2 | |
# $ progress -p $(pidof bzcat) | |
# $ progress # progress of all open files, shows e.g. how far mpd is through your song :P | |
# | |
# source: http://stackoverflow.com/a/238140/69663 | |
set -e -u -o pipefail | |
exec lsof -o0 -o "$@" | | |
awk '$4 ~ /^[0-9]+r$/ && $5 == "REG" && $7 ~ /^0t/ { | |
offset = substr($7, 3) | |
fname = $0; sub(/([^ \t]+[ \t]+){8}/,"",fname) # $9 to NF, but keeping IFS | |
"stat -c %s '\''" fname "'\''" | getline | |
len = $0 | |
if (len) { | |
print fname, offset / len * 100 "%" | |
} | |
}' || echo "lsof returned $? for args '-o0 -o $@'" >&2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment