List file read process in percentage
Table of Content
Script
#!/bin/bash
if ! [[ -f "${1}" ]]; then
echo "Could not find: ${1}"
echo "If relative used file, execute script from same path"
echo "or start both process and script with absolut path"
exit 1
fi
filesize=$(stat -c %s "${1}")
process_pid=$(pgrep -f "${1}")
pos=$(awk '/^pos:/{print $2}' "/proc/${process_pid}/fdinfo/3")
printf "Progress: %.2f%% (%d / %d bytes)\n" "$(awk -v p="$pos" -v s="$filesize" 'BEGIN{print (p*100)/s}')" "$pos" "$filesize"