Bash 从 Web 服务器更新脚本版本

Bash Script Version Updating from a Web Server

我正在尝试通过 www 自动更新脚本。不确定这是否是最好的方法?

# Check for Latest Version, Download Latest If CurrentVersion is not equal to the latest version

CurrentVersion=10.1.1

LatestVersion=$(curl http://www.some-url.com/version.txt)


if [[ $CurrentVersion = $LatestVersion ]]; then echo "Latest Version is Already Installed"; 


else curl --url http://www.some-url.com/download --output ~/Scripts/;


    echo "script is now updated !" 

fi

您可以简单地创建一个 cron 任务来执行以下脚本:

#!/usr/bin/env sh

url="http://www.some-url.com/download"
file="${HOME}/Scripts/Backups/Daily/download"

curl -z "$file" -f "$url" -O "$file"

使用选项 -z 将使 curl 检查 URL 中的文件是否具有比本地文件更新的时间戳。如果是这样,它将更新本地文件。