Dialog progress bar (Shell Script)

Asked

Viewed 161 times

1

I would like to create a progress bar for my backup script. The problem is that the rsync command (which is inside the loop) generates duplicate (unnecessary) lines that increase the size of the log file. I already included inside the loop the command uniq -u to generate single lines, but this command causes a bug in the dialog progress bar (hangs the bar). See a snippet of my code below.

dialog --infobox 'Iniciando Backup...' 3 25; sleep 1
  declare -i cont=1
  {
  while [ $cont -le 100 ]; do
    echo $cont
    cont=$((cont+1))
    rsync -avh --progress "/home/$USER/Documentos" "/home/$USER/Backup/" --log-file=arquivo.log
    uniq -u arquivo.log
  done
  } | dialog --gauge 'Aguarde... Copiando Arquivos' 8 70 0
  dialog --msgbox 'Backup concluído com sucesso!' 6 35
  dialog --title 'Log de Backup' --textbox "$ARQUIVO_LOG" 0 0  

I don’t know how to fix this, would anyone know how to perfect this code? Please test this code and propose improvements. Thanks in advance.

1 answer

1

You can redirect stderr to stdout with 2>&1 thus:

ARQUIVO_LOG=arquivo.log
dialog --infobox 'Iniciando Backup...' 3 25; sleep 1
  declare -i cont=1
  {
  while [ $cont -le 100 ]; do
    echo $cont
    cont=$((cont+1))
    rsync -avh --progress "/home/$USER/Downloads" "/home/$USER/Downloads.bak/" --log-file=$ARQUIVO_LOG 2>&1
    uniq -u $ARQUIVO_LOG
  done
  } | dialog --gauge 'Aguarde... Copiando Arquivos' 8 70 0
  dialog --msgbox 'Backup concluído com sucesso!' 6 35
  dialog --title 'Log de Backup' --textbox "$ARQUIVO_LOG" 0 0  

Looks great:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.