Skip to content

Instantly share code, notes, and snippets.

@h2non
Last active December 23, 2015 15:59
Show Gist options
  • Save h2non/6659017 to your computer and use it in GitHub Desktop.
Save h2non/6659017 to your computer and use it in GitHub Desktop.
wget output simple parsing to show the download process
#!/bin/bash
download_status() {
if [ -f $1 ]; then
while : ; do
sleep 1
local speed=$(echo `cat $1 | grep -oh '\([0-9.]\+[%].*[0-9.][s|m|h|d]\)' | tail -1`)
echo -n "Downloading... $speed"
echo -n R | tr 'R' '\r'
if [ -f $2 ]; then
sleep 1
local error=$(echo `cat $2`)
if [ $error != '0' ]; then
echo
if [ $error == '6' ]; then
echo "Server authentication error, configure setup.ini properly. See the output log"
else
echo "Download error, exit code '$error'. See the output log"
fi
exit $?
fi
break
fi
done
fi
}
# Usage:
`wget http://my.files.org/download.tar.gz > /tmp/download.log 2>&1 && echo $? > /tmp/download_success || echo $? > /tmp/download_success` &
download_status /tmp/download.log /tmp/download_success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment