Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can someone make a simple zenity script for zsync which just takes the location of the file to be synced and the zsync file and show progress ?

share|improve this question
up vote 5 down vote accepted

zsync has terrible output for parsing. You'd be crazy to attempt that.

That said, I'm apparently crazy.



tempdir=$(mktemp -d)
trap 'rm -rf "$tempdir"' EXIT

down_filter() {
    local message line percent speed
    echo "Downloading zsync file" > "$msgfile"
    read -r -n1 _
    while read -r line; do
        if [[ $line = [-#]* ]]; then
            read -r _ percent speed <<< "$line"
            echo "#$(<"$msgfile")\n$speed"
            if (( ${percent%%.*} < 100 )); then
                echo "$percent"
                echo "99.9%"
    done < <(awk 'BEGIN{RS="[\r\n]"} {print;fflush()}')

seed_filter() {
    local message file count size point
    while read -r -d '*' line; do
        echo "$message" > "$msgfile"
        file=${file#reading seed file }
        size=$(( $(wc -c < "$file") / 1000000 + 1 ))
        echo "#$message"
        while read -r -n1 point; do
            [[ $point = '*' ]] || break
            echo "$(( 100 * count / size ))%"
        read -r message;
        echo "$message" > "$msgfile"

if [[ -z $url ]]; then
    url=$(zenity --entry \
                 --title=zsync \
                 --text="Enter URL to zsync file" \
                 --width=500 \
                 --height=100 \
    ) || exit

if [[ -z $seedfile || ! -e $seedfile ]]; then
    seedfile=$(zenity --file-selection \
                      --title="zsync $url" \
                      --text="Choose a seed-file" \

    zsync ${seedfile:+-i "$seedfile"} "$url" \
          > >(down_filter >&3) 2> >(seed_filter >&3)
} 3> >(zenity --progress \
              --title="zsync $url" \
              --width=500 \
              --height=100 \

The script will have a lot of weaknesses. Any slight change in the output of zsync in a newer version would likely break it. (Only tested against Ubuntu 10.04's zsync v0.6.1). For some odd reason it outputs some of the progress to stdout, and some to stderr, which makes it extra hard to parse.

Also, it won't handle certain odd characters in filenames, like \, * or newlines.

Expect bugs; I haven't really tested it that much.

Anyway, I had never heard of zsync before. It's a neat tool, so thanks for letting me know about it at least. :)

Screenshots : enter image description here enter image description here

share|improve this answer
It worked in 10.04 with 0.6.1-1ubuntu1 version of zsync. Thanks – Alaukik Feb 3 '11 at 9:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.