我编写了一个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没有找到。所以我应该怎么做才能永远得到最新的版本。
发布于 2019-04-21 12:24:23
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.xTomcat版本,这个版本一直在变化。
由于下载Tomcat的URL保持不变,只有版本更改,所以我发现以下解决方案对我是有效的:
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.40grep v8 -返回所需版本的行:
<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]}' -提取我们想要的版本:
8.5.40然后,我使用提取的版本下载Tomcat:
wget -N http://mirror.vorboss.net/apache/tomcat/tomcat-8/v${TOMCAT_VER}/bin/apache-tomcat-${TOMCAT_VER}.tar.gz这是使用curl、grep和awk提取版本的完整curl响应:
<!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>发布于 2018-07-10 13:02:48
我找到了一种使用官方github镜像的方法。基本上,我们必须查询github中的所有可用标记。之后,对于每个标记,必须确定日期。最后,带有最新日期的标签就是最新的标签!
试试这个脚本--让我们称它为latest-tag。它依赖于jq。它需要很短的时间来执行,但是应该打印最近标签的tarball的URL (当前:10)。
#!/bin/bash
# Prints the url to the latest tag of given github repo
# $1: repo (e.g.: apache/tomcat )
# $2: optional github credentials. Credentials are needed if running into the api rate limit (e.g.: <user>|<user>:<authkey>)
repo=${1:?Missing parameter: repo (e.g.: apache/tomcat )}
[ -n "$2" ] && credentials="-u $2"
declare -a commits
declare -a tarball_urls
while IFS=, read commit_url tarball_url
do
date=$(curl $credentials --silent "$commit_url" | jq -r ".commit.author.date")
if [[ "$date" > ${latest_date:- } ]]
then
latest_date=$date
latest_tarball_url=$tarball_url
fi
done < <( curl $credentials --silent "https://api.github.com/repos/$repo/tags" | jq -r ".[] | [.commit.url, .tarball_url] | @csv" | tr -d \")
echo $latest_tarball_url用法:
./latest-tag apache/tomcat您可能会受到github的速率限制的阻碍。因此,您可能希望向脚本提供github凭据:
./latest-tag apache/tomcat <username>这将向您询问您的github密码。为了交互地运行它,您可以为脚本提供一个个人github api令牌
./latest-tag apache/tomcat <username>:<api token>发布于 2019-09-03 15:08:51
免责声明-此解决方案使用屏幕刮除
查找并下载用于Linux或Windowsx64的Apache 9的最新版本。
使用Python 3.7.3
import os
import urllib.request
url_ends_with = ".tar.gz\"" # Use line for Non-Windows
url_ends_with = "windows-x64.zip\"" # Use line for Windows-x64
url_starts_with = "\"http"
dir_to_contain_download = "tmp/"
tomcat_apache_org_frontpage_html = "tomcat.apache.org.frontpage.html"
download_page = "https://tomcat.apache.org/download-90.cgi"
try:
if not os.path.exists(dir_to_contain_download):
os.makedirs(dir_to_contain_download, exist_ok=True)
htmlfile = urllib.request.urlretrieve(download_page, dir_to_contain_download + tomcat_apache_org_frontpage_html)
fp = open(dir_to_contain_download + tomcat_apache_org_frontpage_html)
line = fp.readline()
cnt = 1
while line:
line = fp.readline()
cnt += 1
if url_ends_with in line and url_starts_with in line:
tomcat_url_index = line.find(url_ends_with)
tomcat_url = line[line.find(url_starts_with) + 1 : tomcat_url_index + len(url_ends_with) - 1]
print ("Downloading: " + tomcat_url)
print ("To file: " + dir_to_contain_download + tomcat_url[tomcat_url.rfind("/")+1:])
zipfile = urllib.request.urlretrieve(tomcat_url, dir_to_contain_download + tomcat_url[tomcat_url.rfind("/")+1:])
break
finally:
fp.close()
os.remove(dir_to_contain_download + "/" + tomcat_apache_org_frontpage_html)https://stackoverflow.com/questions/51258801
复制相似问题