estimate.sh

A cool script whoted by myself to calculate the remaining time to a file achieve a number of lines.

devtools:/srv/scripts # cat estimate.sh
#!/bin/bash
# estimate the remaining time for a file to achieve a number
# of lines
# usage
# <scriptName> <fileName> <totaloflines>
file="$1";
vmax=$2;
tini=$(date +%s);
vini=$(cat $file | wc -l);
while ( sleep 1 );
do
# get the current number of rows
vact=$(cat $file | wc -l);
# get the rows recovered since the start of script
vela=$((vact-vini));
# get the current time in seconds
tact=$(date +%s);
# get the time elapsed in seconds since the start of script
tela=$((tact-tini));

# discover the average of rows added per second
if (( $tela > 0 )); then
vave=$((vela / tela));
fi;
# get rows remaining
vrem=$(( vmax - vact ))
# get the estimated remaining time
if (( $vave > 0 )); then
trem=$(( vrem / vave ))
fi;

hr=$((trem / 3600 ))
mr=$((trem / 60 % 60 ))
sr=$((trem % 60 ))

echo "Linhas processadas: $vact; linhas restantes: $vrem; tempo restante: $hr:$mr:$sr;";
done;
Postar um comentário

Postagens mais visitadas