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

Comments (2)

Thomas Goirand

Did you try to run this against the number of RC bugs in Jessie? :)

Feb. 1, 2015, 12:05 a.m. #
Uli Martens

and you can even modify it easily to count up to something: (sorry for the probably broken paste, don't know the syntax of this pastebox)

{{{
eta2val () {
v=$1
shift
A=$(($v-$(eval ${@})))

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

Feb. 3, 2015, 8:09 a.m. #