› Foros › PC › Software libre
function progreso()
{
percent=`awk 'BEGIN{printf("%0.2f", '$1' / '$2' * 100)}'`
MESSAGE="Progreso de ficheros $EXT: $percent %: "
let COLUMNA=$(tput cols)-$(echo $MESSAGE | wc -m)-2
echo -en "\r";
echo -en "$MESSAGE"
let barra=$1*$COLUMNA; let barra=$barra/$2;let barra2=$COLUMNA-$barra;
if [ $barra -eq $COLUMNA ];then
for j in `seq 1 $barra`;do
echo -en "\033[44m ";
done
else
for j in `seq 1 $barra`;do
echo -en "\033[41m ";
done
for k in `seq 1 $barra2`;do
echo -en "\033[47m ";
done
fi
echo -en "||\033[40m"
}
#!/bin/bash
# description: Ejemplo Barra de progreso
sh_processname="$0"
sh_author="rcarrera"
sh_version="0.1"
sh_date="05/02/2013"
###Variables
MAX=10
##Funciones
function progreso()
{
percent=`awk 'BEGIN{printf("%0.2f", '$1' / '$2' * 100)}'`
MESSAGE="Progreso de ficheros $EXT: $percent %: "
let COLUMNA=$(tput cols)-$(echo $MESSAGE | wc -m)-2
echo -en "\r";
echo -en "$MESSAGE"
let barra=$1*$COLUMNA; let barra=$barra/$2;let barra2=$COLUMNA-$barra;
if [ $barra -eq $COLUMNA ];then
for j in `seq 1 $barra`;do
echo -en "\033[44m ";
done
else
for j in `seq 1 $barra`;do
echo -en "\033[41m ";
done
for k in `seq 1 $barra2`;do
echo -en "\033[47m ";
done
fi
echo -en "||\033[40m"
}
##Cuerpo
for i in `seq 1 $MAX`;do
progreso $i $MAX
sleep 1
done
echo -e "\nHa terminado"
exit 0
#!/bin/bash
# description: Ejemplo Barra de progreso
sh_processname="$0"
sh_author="rcarrera"
sh_version="0.2"
sh_date="05/02/2013"
###Variables
MAX=10
TIME_S=10
##Funciones
function progreso()
{
tput sc; tput cup 0 0;
percent=`awk 'BEGIN{printf("%0.2f", '$1' / '$2' * 100)}'`
MESSAGE="Progreso del script: $percent %: "
let COLUMNA=$(tput cols)-$(echo $MESSAGE | wc -m)-2
echo -en "\r";
echo -en "$MESSAGE"
let barra=$1*$COLUMNA; let barra=$barra/$2;let barra2=$COLUMNA-$barra;
if [ $barra -eq $COLUMNA ];then
for j in `seq 1 $barra`;do
echo -en "\033[44m ";
done
else
for j in `seq 1 $barra`;do
echo -en "\033[41m ";
done
for k in `seq 1 $barra2`;do
echo -en "\033[47m ";
done
fi
echo -en "||\033[40m"
tput rc;
}
#####SLEEP_TIME
#Funcion para mostrar el tiempo de espera
function sleep_time()
{
tput sc
while [ $TIME_S -ne 0 ];do
tput cup 1 0;tput el;
echo -en "Tiempo de espera previo a continuar: $TIME_S"
sleep 1
let TIME_S=$TIME_S-1
done
echo -en "\r"; tput el; tput rc
}
##Cuerpo
clear; tput cup 2 0;
for i in `seq 1 $MAX`;do
progreso $i $MAX
echo "Vamos por la posición $i"
sleep 1
done
sleep_time;
echo -e "\nHa terminado"
exit 0