Skip to main content

Piping of stream from wget to tar, and extracting it to a specific location failed [Resolved]

I try to pipe a stream from wget to tar and extracting it to a specific location.
The file is downloaded by wget but not extracted as desired with tar:

war="/var/www/html"
domain="example.com"
downloaded_file="https://releases.wikimedia.org/mediawiki/1.33/mediawiki-1.33.0.tar.gz"
wget -P "${war}" "${downloaded_file}" | tar -xzvf ${downloaded_file} --transform="s,^${downloaded_file},${domain},"

set -x error:

tar: unrecognized option:
`--transform=s,^https://releases.wikimedia.org/mediawiki/1.33/mediawiki-1.33.0.tar.gz,example.com,'

Why piping of stream from wget to tar, and extracting it to a specific location failed?


Question Credit: JohnDoea
Question Reference
Asked August 21, 2019
Tags: pipe, wget
Posted Under: Unix Linux
28 views
3 Answers

You're writing the downloaded data to a file, so you're not actually piping anything to tar. Pipes are only useful if you want the standard output of one program to become the standard input of another. Here, you are downloading a file and then want to open it with another tool, so pipes aren't useful.

The next issue is that your $downloaded_file is actually a URL. So when you tar -xzvf ${downloaded_file} you're actually running tar -xzvf https://releases.wikimedia.org/mediawiki/1.33/mediawiki-1.33.0.tar.gz and that will fail since that file doesn't exist (it's not a file, it's an internet address).

What you want to do is something like this:

war="/var/www/html"
targetUrl="https://releases.wikimedia.org/mediawiki/1.33/mediawiki-1.33.0.tar.gz"
fileName="${targetUrl##*/}"
wget "$targetUrl" -O "$war/$fileName" && 
    tar -xzvf "$war/$fileName"

I don't see why the -P option of wget would be relevant here, nor why you would need the --transform from tar, but if you must use it, you can do:

war="/var/www/html"
domain="example.com"
targetUrl="https://releases.wikimedia.org/mediawiki/1.33/mediawiki-1.33.0.tar.gz"
wget "$targetUrl" -O "$war/$fileName" && 
    tar -xzvf "$war/$fileName" --transform="s,^${targetUrl},${domain},"

I really doubt you do want these though. Why would https://releases.wikimedia.org/mediawiki/1.33/mediawiki-1.33.0.tar.gz be part of the paths in the mediawiki-1.33.0.tar.gz archive?


credit: terdon
Answered August 21, 2019

wget -qO - "https://releases.wikimedia.org/mediawiki/1.33/mediawiki-1.33.0.tar.gz" | tar -C /var/www/html zxvf -


credit: markgraf
Answered August 21, 2019
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA