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:

wget -P "${war}" "${downloaded_file}" | tar -xzvf ${downloaded_file} --transform="s,^${downloaded_file},${domain},"

set -x error:

tar: unrecognized option:

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
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 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:

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:

wget "$targetUrl" -O "$war/$fileName" && 
    tar -xzvf "$war/$fileName" --transform="s,^${targetUrl},${domain},"

I really doubt you do want these though. Why would be part of the paths in the mediawiki-1.33.0.tar.gz archive?

credit: terdon
Answered August 21, 2019

wget -qO - "" | tar -C /var/www/html zxvf -

credit: markgraf
Answered August 21, 2019
Your Answer