January 30th 2015

Calculating the ETA to zero in shell

< 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...)




You can subscribe to new posts via email or RSS.