本文介绍了如何使用shell获取下载tomcat服务器的最新链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个shell脚本来下载和安装tomcat服务器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 工作正常,但是一旦版本更改为 9.0.10,它就开始出现 404 not found 错误.那么我应该怎么做才能始终获得最新版本.

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.

推荐答案

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

我遇到了同样的挑战.但是,对于我的解决方案,我需要不断变化的最新 8.5.x Tomcat 版本.

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

由于下载Tomcat的URL保持不变,只是版本发生了变化,我发现以下解决方案适合我:

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 - 返回具有所需版本的行:

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]}' - 提取我们想要的版本:

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

8.5.40

然后我继续使用提取的版本下载 Tomcat:

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

这是使用 curl、grep 和 awk 从中提取版本的完整 curl 响应:

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>

这篇关于如何使用shell获取下载tomcat服务器的最新链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 15:50