Bash – Pipe command output to Yad and also log the output to a logfile

bashio-redirectionpipeshell-script

Need to have the process of command typically an update to be shown using yad and at the same time log all the output to a given log file set up.
This is what I have

apt-get update | yad --width=400 --height=300 \
--title="Updating debian package list ..." --progress \
--pulsate --text="Updating debian package list ..." \
--auto-kill --auto-close \
--percentage=10 

The above command creates a pulsating indicator for the process and closes on finish but I need to have it log all the output it gives I have tried

apt-get update >>${logfile} 2>&1 | yad --width=400 --height=300 \
--title="Updating debian package list ..." --progress \
--pulsate --text="Updating debian package list ..." \
--auto-kill --auto-close \
--percentage=10 

but that gives me an error and hangs from there on no dialog and no logging just freezing. Here is the error

 GLib-CRITICAL **: g_source_remove: assertion `tag > 0' failed

Help appreciated

Best Answer

The error is because you are redirecting all output to $logfile so there is no output for yad to process. The tool you're looking for is tee:

NAME
       tee - read from standard input and write to standard output and files

SYNOPSIS
       tee [OPTION]... [FILE]...

DESCRIPTION
       Copy standard input to each FILE, and also to standard output.

So, you could do:

apt-get update 2>&1 | tee -a ${logfile} |
  yad --width=400 --height=300 \
    --title="Updating debian package list ..." --progress \
    --pulsate --text="Updating debian package list ..." \
    --auto-kill --auto-close \
    --percentage=10 
Related Question