92

I have a Bash script that creates a .tar.gz file, encrypts, and then sends it to a drive. However, I cannot open the .tar.gz file afterwards. Here is my process...

Bash script that encrypts.

#!/bin/sh

# Tar the automysqlbackup directory
tar -zcf "red-backup-$(date '+%Y-%m-%d').tar.gz" /var/lib/automysqlbackup/

# Encrypt the tar file
openssl aes-256-cbc -a -salt -in "red-backup-$(date '+%Y-%m-%d').tar.gz" -out "red-backup-$(date '+%Y-%m-%d').tar.gz.enc" -pass 'pass:MySecretPWD'

# Remove the original tar file
rm -rf "red-backup-$(date '+%Y-%m-%d').tar.gz"

# Upload to Google Drive
gdrive upload --file "red-backup-$(date '+%Y-%m-%d').tar.gz.enc" -p "jofhriout849uioejfoiu09"

Then I download the file and use

sudo openssl aes-256-cbc -e -in red-backup-2016-09-22.tar.gz.enc -out red-backup-2016-09-22.tar.gz

I then enter the passphrase for my file twice and I now get a file called

red-backup-2016-09-22.tar.gz

When I then try

sudo tar -zxvf red-backup-2016-09-22.tar.gz

I get

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now

I have also tried renaming the file .tar and also tried

sudo tar xvf red-backup-2016-09-22.tar.gz

and

sudo tar xvf red-backup-2016-09-22.tar

tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

Where am I going wrong?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ServerSideSkittles
  • 2,713
  • 10
  • 34
  • 60
  • 11
    Can you try unpacking a tar without the `z` ? – Inian Sep 22 '16 at 15:27
  • 1
    without the z flag I get the same error stdin: not in gzip format. Without both z flag and filename .tar (no .gz) I get " tar: This does not look like a tar archive " – ServerSideSkittles Sep 22 '16 at 15:30
  • 1
    leave out the `-a` flag during encryption (or use it also during decryption if you need to base64 process the data) and use `-d` to decrypt, not `-e` (in the example above, the file was encrypted twice) – ewcz Sep 22 '16 at 15:41
  • @ewcz With the -a flag removed and using -d as you said, the process worked flawlessly. Thankyou very much for solving the problem. – ServerSideSkittles Sep 22 '16 at 22:21
  • Solved this issue by installing the binary version, refer [this](https://cassandra.apache.org/doc/latest/cassandra/getting_started/installing.html). Cassandra 4.0.0 isn't available, you can find 4.0.3 over [here](https://downloads.apache.org/cassandra/4.0.3/) – Suraj Feb 25 '22 at 15:30

9 Answers9

89

First check the type of compression using the file command:

file name_name.tgz

Output: If the output is " XZ compressed data", then use tar xf <archive name> to unzip the file, e.g.

  • tar xf archive.tar.xz

  • tar xf archive.tar.gz

  • tar xf archive.tar

  • tar xf archive.tgz

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kamran kausar
  • 4,117
  • 1
  • 23
  • 17
84

This means the file isn't really a gzipped tar file -- or any kind of gzipped file -- in spite of being named like one.

When you download a file with wget, check for indications like Length: unspecified [text/html] which shows it is plain text (text) and that it is intended to be interpreted as html. Check the wget output below -

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz"

--2017-10-12 12:39:40--  http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz
Resolving download.oracle.com (download.oracle.com)... 23.72.136.27, 23.72.136.67
Connecting to download.oracle.com (download.oracle.com)|23.72.136.27|:80... connected.
HTTP request sent, awaiting response... 302 Not Allowed
Location: http://XXXX/FAQs/URLFiltering/ProxyWarning.html [following]
--2017-10-12 12:39:40--  http://XXXX/FAQs/URLFiltering/ProxyWarning.html
Resolving XXXX (XXXXX)... XXX.XX.XX.XXX
Connecting to XXXX (XXXX)|XXX.XX.XX.XXX|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 17121 (17K) [text/html]
Saving to: ‘jdk-8u144-linux-x64.tar.gz’

100%[=========================================================================================================================================================================>] 17,121      --.-K/s   in 0.05s

2017-10-12 12:39:40 (349 KB/s) - ‘jdk-8u144-linux-x64.tar.gz’ saved [17121/17121]

This sort of confirms that you haven't received a gzip file.

For a correct file, the wget output will show something like Length: 185515842 (177M) [application/x-gzip] as shown in the below output -

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz"

--2017-10-12 12:50:06--  http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz
Resolving download.oracle.com (download.oracle.com)... XX.XXX.XX.XX, XX.XX.XXX.XX
Connecting to download.oracle.com (download.oracle.com)|XX.XX.XXX.XX|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz [following]
--2017-10-12 12:50:06--  https://edelivery.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz
Resolving edelivery.oracle.com (edelivery.oracle.com)... XXX.XX.XXX.XX, 2600:1404:16:188::2d3e, 2600:1404:16:180::2d3e
Connecting to edelivery.oracle.com (edelivery.oracle.com)|XXX.XX.XX.XXX|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz?AuthParam=1507827127_f44251ebbb44c6e61e7f202677f94afd [following]
--2017-10-12 12:50:07--  http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz?AuthParam=1507827127_f44251ebbb44c6e61
Connecting to download.oracle.com (download.oracle.com)|XX.XX.XXX.XX|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 185515842 (177M) [application/x-gzip]
Saving to: ‘jdk-8u144-linux-x64.tar.gz’

100%[=========================================================================================================================================================================>] 185,515,842 6.60MB/s   in 28s

2017-10-12 12:50:34 (6.43 MB/s) - ‘jdk-8u144-linux-x64.tar.gz’ saved [185515842/185515842]

The above shows a correct gzip application file has been downloaded.

You can also file, head, less, view utilities to check the file. For example, an HTML file would give the below output -

head jdk-8u144-linux-x64.tar.gz

Output:

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="/css/print.css" rel="stylesheet" media="print">
    <link href="/css/main.css" rel="stylesheet" media="screen">
    <link href="/css/font-awesome.min.css" rel="stylesheet">

The above shows it is indeed an HTML page which we are trying to unzip/untar - something that won't work. If it was indeed a correct zip file (binary in nature) the output of head would have produced garbage - something like below -

head jdk-8u144-linux-x64.tar.gz

Output:

x�rY�[ms�F������ڍtіl���DR���Ŋ��j
                                       $�$,`0�h�_����/��=�@Q�w+��ձ*�Hbfz�{�~�{�i�x��k����޾}����z���w����g�����{�޼�;{s����w���⹳�7�N����i�
�����}
�¿g��������ק���7��s�����폺î߹�����~i��j�/�����޿#���=��=>��߿{}��|�������������3���X���]9�ޠ����u�����%ğ�<^)�H�8�F�R�t�o�L�u��S%�ds5�2_EZn�t^��
                                                                                                                                                 �N3��(��<��|'�q���R�N�gq�Uv!�ۻ�p���rL��M��u��.�Q�5�T��BNw�!$��<>�7G'$�,Mt4WY�Gi"�=��p�)�VIN3����\ek��0��G
                                            �<L�c�ē�t-���2���G:Ϣia��I�<ʋg3���d�H����[2`�<I�A�6�W��<��C�������h��A0QL�2�4�-*
�x���Е�t%t1��f�>+A͂�,Lr�
                        �Fe:MBH��ɩ�
C�Q�r�S��<M�b�<,5���@���s��݉c��sp�f�=g��?��k���4�}��kh)�¹Z��#d�*{���-�.N�)�e��s:�H(VQ��3*�$2��rϨv�"o�_��!A�������B�l=A�|��@��0��1��5��4g�
�
���Se����H[2�����t��5�Df����$1���b$� h�Op����!Lvb!p��b�8^�Y���n�
                                                                          O��Ԫ߱��|��lW�lu��*�N�M���
�/�^0~�~�#��q��������K��;�d���aw4����ݎ'�~�7��ky�o���������t�'k��f����!vo���'o���     �.�Pn\�
               �+��K"FA{����n2����v��!/Ok��r4�c5�x$'�.�&w�!�%�ޠo������2���i
                                                                               �a0��Ag�d����GH)G7~�g���b��%�b��rt�m~�    �����t0��    <������������5�q�t��K(��+Z<��=���:1�\�x�p=t�`��G@F��    i�����p8�����H.���dMLE��e[�`�'n��*h[��;�0w'��6A�١M�x�fpeB>&���MO�������`�@á/�"�����(��^���n��=����5��@�Mx��d:\YAn���]|�w>��S��FA9�J�k!�@�

Try downloading from the official site and check if their download links have changed. Also check your proxy settings and make sure you have the right proxies enabled to download/wget it from the correct source.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Souvik
  • 865
  • 6
  • 8
  • Thanks, this is what I was looking for, I was trying to wget jdk but didn't noticed it required auth code for download, and was indeed downloading the html page. – Aditya T Jan 11 '18 at 11:17
  • 1
    One way of wget downloading jdk is to download it with chrome just like a normal file and then get the url link from the downloads. do a wget on the remote machine. You'll see a file something like jdk-9.0.4_linux-x64_bin.tar.gz?AuthParam=1520.... just untar it. – karthik101 Mar 06 '18 at 14:18
  • for me, I was downloading a html page by accident so the answer helped me confirm it. I cannot upvote it as it's at 69 votes though – Ayudh Oct 18 '21 at 15:46
28

Just click first on that link and go to the HTML page where actual downloads or mirrors are.

It's really misleading to have a full link which ends in .tgz when it actually leads to an HTML page where the real download links are.

I had this problem downloading Apache Spark and Wget-ing it into Ubuntu.

https://spark.apache.org/downloads.html
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hrvoje
  • 13,566
  • 7
  • 90
  • 104
  • 3
    I faced the same issue when downloading the latest version of spark. Glad I came across this comment, helped me fix the issue. – Saurabh Jain Oct 15 '19 at 07:21
  • Also after selecting download spark, it leads to this page.. https://www.apache.org/dyn/closer.lua/spark/spark-2.3.4/spark-2.3.4-bin-hadoop2.7.tgz and there you can find the mirror link for spark (don't always check the URL name) – Rohit Chauhan Nov 07 '19 at 10:17
  • elaborate please – Mohammad Heydari Sep 18 '20 at 22:10
  • @MohammadHeydari when you have link in your browser in address bar which ends with .../htmlpage.pdf for example, it doesn't necessary means that it's really pdf file behind it - it could be just another HTML page. – Hrvoje Sep 21 '20 at 07:28
9

Initially, check the type of compression with the below command:

`file <file_name>`

If the output is a POSIX compressed file, use the below command to uncompress:

`tar xvf <file_name>`
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Laxmi Allagi
  • 91
  • 1
  • 1
1

Sometimes the .gz extension is wrongfully appended to the filename.

  • Run file foo.csv.gz to know the actual file type.
  • Rename the file to foo.csv or whatever the actual file type is.
P-S
  • 3,876
  • 1
  • 29
  • 26
0

Add "-O file.tgz" or "-O file.tar.gz" at the end of the wget command and extract "file.tgz" or "file.tar.gz".

Here is the sample code for Google Colaboratory:

!wget -q  --trust-server-names  https://downloads.apache.org/spark/spark-3.0.0/spark-3.0.0-bin-hadoop2.7.tgz  -O file.tgz
print("Download completed successfully !!!")
!tar zxvf  file.tgz

Note: Please ensure that the http path for tgz is valid and the file is not corrupted.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
-1

unxz worked for me:

sudo unxz fileName.xz
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rajat
  • 9
-2
cd /Whatever/Directory/Path/The/File/Is/In

chmod +x xampp-linux-x64-7.0.6-0-installer.run

sudo ./xampp-linux-x64-7.0.6-0-installer.run

It works.

For more information, refer to Installing XAMPP on Linux Mint.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 2
    What does this have to do with a question about an archive created with tar and openssl? Your `.run` archive is created with a `shar`-style tool, which is completely different and not compatible with the tools this question is asked about. – Charles Duffy Jul 23 '19 at 19:02
-15

This is probably because of your gzip version incompatibility.

Check these points first:

which gzip

/usr/bin/gzip or /bin/gzip

It should be either /bin/gzip or /usr/bin/gzip. If your gzip points to some other gzip application, please try by removing that path from your PATH environment variable.

Next is

gzip -V

gzip 1.3.5 (2002-09-30)

Your problem can be resolved with these check points.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Roopendra
  • 40
  • 4