Score:4

I need a zenity progress bar using the output of shred

mx flag

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.

Score:7
jp flag

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"
muru avatar
us flag
A pipe continues to the next line, you don't need to escape the newline with ``\``.
Raffa avatar
jp flag
@muru True ... The escapes, however, are for compatibility and history ... Not all shells handle multi-line commands equally, I think ... See for example [multiline command chunks in bash history into multiple lines](https://askubuntu.com/q/1133015)
BlackRed avatar
mx flag
Thank you. The second one did work I only had to put ( ) around everything before " | zenity --progress". I also deleted $NF+0 because the progress bar took the values to move the bar forward but I only wanted to get the output of shred in the text section of --progress.
Raffa avatar
jp flag
@BlackRed You can show both ... I updated the answer for that ... And I don't see why you might need to use the sub-shell `( ... )` syntax for that
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.