0

Recently MaxMind changed their download policy, and the old simple format is no longer available. The new file format looks like this: GeoLite2-Country_20191231.tar.gz, and inside we have a folder with the same name containing two additional files.

Although there is an option to delete the date parameter from the link, it seems that the downloaded file will still contain the date.

Now, the problem is to extract that GeoLite2-Country.mmdb from the gzip file having that variable name programmatically.

The unzip part existing in my old script was this:

gunzip -c "$1"GeoLite2-Country.mmdb.gz > "$1"GeoLite2-Country.mmdb

The question is how to modify the above part for the new situation. Or, maybe someone knows another way to solve the same problem. Thanks in advance.

The folder structure:

-+ Geolite2-Country_YYYYMMDD.tar.gz:
 |-+ Geolite2-Country_YYYYMMDD
   |- licence.txt
   |- copyright.txt
   |- Geolite2-Country.mmdb

What I need is Geolite2-Country.mmdb in the current folder of gzip file.

Sorin GFS
  • 477
  • 3
  • 18
  • Quick and dirty? `GeoLite2-Country_*.mmdb.gz` would work if you only have one of those files in the directory. – kaylum Jan 04 '20 at 19:50
  • @kaylum I said that there are multiple files now, not just one, and the database name doesn't match the folder name. – Sorin GFS Jan 04 '20 at 20:16
  • Then write a shell script with a `for` loop. The `for` loop would iterate over `GeoLite2-Country*.mmdb.gz`. Then [extract the filename without extension](https://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash) for the `mmdb` file name. – kaylum Jan 04 '20 at 20:22
  • @kaylum Thanks for the idea, but I'm not so familiar with loops. I updated the question with the folder structure, can you try to write the script? – Sorin GFS Jan 04 '20 at 20:43

1 Answers1

0
tar -tf /GeoLite2-City.tar.gz | grep mmdb | xargs tar -xf  /GeoLite2-City.tar.gz --strip-components 1 -C /

Just fix source and destination paths