Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get always latest link to download tomcat server using shell

Tags:

shell

tomcat

I have written a shell script to download and install the tomcat server v (8.5.31). wget http://www.us.apache.org/dist/tomcat/tomcat-8/v8.5.31/bin/apache-tomcat-8.5.31.tar.gz It was working fine, but as soon the version got changed to 9.0.10, it started giving error as 404 not found. So what should I do to get the latest version always.

like image 748
FLASH Avatar asked Jan 19 '26 11:01

FLASH


1 Answers

TL;DR

TOMCAT_VER=`curl --silent http://mirror.vorboss.net/apache/tomcat/tomcat-8/ | grep v8 | awk '{split($5,c,">v") ; split(c[2],d,"/") ; print d[1]}'`
wget -N http://mirror.vorboss.net/apache/tomcat/tomcat-8/v${TOMCAT_VER}/bin/apache-tomcat-${TOMCAT_VER}.tar.gz

I encountered the same challenge. However for my solution I require the latest 8.5.x Tomcat version which keeps changing.

Since the URL to download Tomcat remains the same, with only the version changing, I found the following solution works for me:

TOMCAT_VER=`curl --silent http://mirror.vorboss.net/apache/tomcat/tomcat-8/ | grep v8 | awk '{split($5,c,">v") ; split(c[2],d,"/") ; print d[1]}'`
echo Tomcat version: $TOMCAT_VER
Tomcat version: 8.5.40

grep v8 - returns the line with the desired version:

<img src="/icons/folder.gif" alt="[DIR]"> <a href="v8.5.40/">v8.5.40/</a>                2019-04-12 13:16    - 

awk '{split($5,c,">v") ; split(c[2],d,"/") ; print d[1]}' - Extracts the version we want:

8.5.40

I then proceed to download Tomcat using the extracted version:

wget -N http://mirror.vorboss.net/apache/tomcat/tomcat-8/v${TOMCAT_VER}/bin/apache-tomcat-${TOMCAT_VER}.tar.gz

This is the complete curl response from which the version is extracted using curl, grep and awk:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of /apache/tomcat/tomcat-8</title>
 </head>
 <body>
<h1>Index of /apache/tomcat/tomcat-8</h1>
<pre><img src="/icons/blank.gif" alt="Icon "> <a href="?C=N;O=D">Name</a>                    <a href="?C=M;O=A">Last modified</a>      <a href="?C=S;O=A">Size</a>  <a href="?C=D;O=A">Description</a><hr><img src="/icons/back.gif" alt="[PARENTDIR]"> <a href="/apache/tomcat/">Parent Directory</a>                             -   
<img src="/icons/folder.gif" alt="[DIR]"> <a href="v8.5.40/">v8.5.40/</a>                2019-04-12 13:16    -   
<hr></pre>
<address>Apache/2.4.25 (Debian) Server at mirror.vorboss.net Port 80</address>
</body></html>
like image 107
Jonathan Avatar answered Jan 21 '26 03:01

Jonathan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!