Shell Script for Postgresql Download

Asked

Viewed 55 times

0

I am writing a code in Shell Script to download the source code of the last updated version of Postgresql checking the current version automatically.

So based on that I did the following:

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)}

She returns it to me below:

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

As I create the command to take the larger value of the folder inside the link so if I run it take the name of the folder "V10.3" and successively if the version is 10.4?

to then give the following exit:

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

URL_DB=https://ftp.postgresql.org/pub/source/v10.3

1 answer

2


Maybe the Sort -V may help you in this matter.

Example:

#!/bin/bash

base_url="https://ftp.postgresql.org/pub/source/"
href_pattern='s/.*href="\([^"]*\).*/\1/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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.