Calculating the ETA to zero in shell

By Chris Lamb

< Faux> I have a command which emits a number. This number is heading towards zero. I want to know when it will arrive at zero, and how close to zero it has got.

Damn right you can.

eta2zero () {
    A=$(eval ${@})

    while [ ${A} -gt 0 ]
    do
        B=$(eval ${@})
        printf %$((${A} - ${B}))s
        A=${B}
        sleep 1
    done | pv -s ${A} >/dev/null
}

In action:

$ rm -rf /big/path &
[1] 4895
$ eta2zero find /big/path \| wc -l
10 B 0:00:14 [   0 B/s] [================================>    ] 90% ETA 0:00:10

(Sincere apologies for the lack of strace...)


Chris Lamb is a freelance software developer and the current Debian Project Leader. You can read other posts by me, see software I have written or read more about me. You can also follow me @lolamby.


Tags: Hacks

Planets: ALUG UWCS WUGLUG Debian

Friday 30th January 2015


Two comments