Hi.
There is a script at linux - Showing total progress in rsync: is it possible? - Server Fault by author nito near the end of the thread.
I copied it into a file I call watch-running-process
Here is a driver script:
#!/usr/bin/env bash
# @(#) s1 Demonstrate rate, ETA of running process, assumes /proc IO, like cp, rsync, etc.
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
em() { pe "$*" >&2 ; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C
SOURCE=/not-backed-up
DESTIN=/tmp
volume=$( du -s -BM $SOURCE | sed 's/M.*$//' )
cp -r $SOURCE $DESTIN &
my_pid=$!
./watch-running-process "$my_pid" "$volume"
exit 0
The parameters are the PID you are watching, the volume of the source in MB, and an optional delay for the loop (default 5 seconds). Because you supply the PID, you can run anything you want, just as long as it does io that is captured in /proc
(so not Solaris, macOS, BSD, etc.). I have not looked in detail at the numbers in /proc, but the script seems to work. If you are interested / curious, see man proc
, look at the entry for io, read_bytes, etc.
Here are display snapshots near the beginning, middle, and end of the process for cp
as done prior to the call to the monitoring script:
Monitoring PID: 29096
Read : 539.04 MiB in 5.03 s
Write: 651.68 MiB in 5.03 s
Read Rate : 107.16 MiB/s ( Avg: 58.05, Max: 126.64 )
Write Rate: 129.55 MiB/s ( Avg: 193.95, Max: 544.66 )
Done : 7.63 GiB / 14.11 GiB (54.07 %)
ETA : 00:00:34.21 (34.21s)
Elapsed : 00:41
-----
Monitoring PID: 29096
Read : 336.91 MiB in 5.04 s
Write: 337.91 MiB in 5.04 s
Read Rate : 66.84 MiB/s ( Avg: 50.63, Max: 126.64 )
Write Rate: 67.04 MiB/s ( Avg: 107.78, Max: 544.66 )
Done : 13.24 GiB / 14.11 GiB (93.83 %)
ETA : 00:00:08.26 (8.26s)
Elapsed : 02:08
-----
Monitoring PID: 29096
Read : 105.94 MiB in 5.03 s
Write: 105.86 MiB in 5.03 s
Read Rate : 21.06 MiB/s ( Avg: 50.43, Max: 126.64 )
Write Rate: 21.04 MiB/s ( Avg: 101.45, Max: 544.66 )
Done : 13.96 GiB / 14.11 GiB (98.93 %)
ETA : 00:00:01.51 (1.51s)
Elapsed : 02:23
----- Finished -----
There is not a real progress bar, but it includes an ETA, along with data rates. Given that the numbers are all available in the script, a scaled progress bar probably could be done.
Best wishes ... cheers, drl