PostgreSQL Download Script Shell

0

I am writing a code in Shell Script to download the source code of the latest updated version of PostgreSQL by checking the link to the current version automatically.

So based on this I did the following:

I created the variable URL_PKG

URL_PG=${URL_PG:-https://ftp.postgresql.org/pub/source} 

The current version of PostgreSQL is 10.3

So I created the following variable:

bash-4.4$ echo SVERSION=${SVERSION:-$(lynx --dump ${URL_PG}|awk -F'/' '/v[0-50]/ {print $1}'|cut -c8-12)}

It returns me this below:

SVERSION=1.08 1.09 10.0 10.1 10.2 10.3 ttps: ttps: ttps: ttps: ttps: ttps:

How do I create the command to get the highest value of the folder inside the link so if I run it get the name of the folder "v10.3" and successively if the version is 10.4?

then give the following output:

bash-4.4$ echo URL_DB=${URL_DB:-${URL_PG}/${SVERSION}}

URL_DB=https://ftp.postgresql.org/pub/source/v10.3
    
asked by anonymous 05.03.2018 / 08:07

1 answer

2

Perhaps the sort -V can help you with this issue.

Example:

#!/bin/bash

base_url="https://ftp.postgresql.org/pub/source/"
href_pattern='s/.*href="\([^"]*\).*//p'

last_version=$(curl -s $base_url | sed -n $href_pattern | grep "v" | sort -V | tail -n 1)
last_url=$base_url$last_version

echo $last_url
    
05.03.2018 / 16:26