4

I want to use the output of shred to make a progress bar with zenity.

My shred command looks like this.

sudo shred -vfn 1 /dev/sda

I am new to Linux. So I probably miss an obvious solution.

Raffa
  • 34,963

1 Answers1

7

A progress bar is easy ... I guess what you are asking about is how to make it update and reflect the output status from shred ... Well, you can use something like this:

shred -vfn 1 file_toshred |& \
while read -r line; do awk '{print $NF+0}' <<<"$line"; done | \
zenity --progress

Notice: I changed sudo shred -vfn 1 /dev/sda to shred -vfn 1 file_toshred for safety reasons of folks testing the code, but that would work as well.

The |& will pipe stderr(needed for parsing shred's output) as well as stdout in Bash ... For other shells not supporting it you might use 2>&1 instead and probably change the herestring(<<<"$line") syntax to an echo "$line" | ... like so:

shred -vfn 1 file_toshred 2>&1 | \
while read -r line; do echo "$line" | \
awk '{print $NF+0}'; done | \
zenity --progress

To print the output text as well, you can add echo "# $line"; inside the while ... loop and you might want to expand the zenity window to accommodate the output by setting the --width= like so:

shred -vfn 1 file_toshred 2>&1 | \
while read -r line; do echo "$line" | \
awk '{print $NF+0}'; echo "# $line"; done | \
zenity --progress --width="500"
Raffa
  • 34,963