【问题标题】:Format URL with the system date in bash在 bash 中使用系统日期格式化 URL
【发布时间】:2021-08-01 06:10:15
【问题描述】:

仅当给定的 URL 已启动时,我才会运行 .sh 脚本以从服务器执行操作。 我每天获取数据更新的 URL(但我不确切知道它的更新时间)。

一个 cron 作业会每五分钟运行一次这个脚本,一旦更新的 URL 存在,它就会运行一个 Rscript。 我对 curl 或 bash 的了解不够,无法根据系统更新日期。

我想在 BASH 中编写一个如下所示的代码:

 if curl -s --head  --request GET https://example.com-2021-05-10 | grep "200 OK" > /dev/null; then 
   Rscript ~/mybot.R
else
   echo "the page is not up yet"
 fi

【问题讨论】:

    标签: bash shell curl cron


    【解决方案1】:

    只需使用date 命令。

     if curl -s --head  --request GET https://example.com-$(date '+%Y-%M-%d') | grep "200 OK" > /dev/null; then 
       Rscript ~/mybot.R
    else
       echo "the page is not up yet"
     fi
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-30
      • 2020-12-03
      • 2018-12-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-16
      • 1970-01-01
      相关资源
      最近更新 更多