如何在 shell 脚本中的 curl 命令中使用当前日期


#!/bin/bash
currentTime=$(date +"%R")
currentdate=$(date +'%m/%d/%Y')
oldtime=$(date +%R -d "50 min ago")
echo "Current time : $currentTime"
echo "Current Date : $currentdate"
echo "Old time : $oldtime"
Response=$(curl -X GET -H "Authorization: Basic Token=" "http://targetserver.company.com:8080/v1/organizations/company/environments/environmentname/stats/apis?select=sum(is_error)&timeRange="$currentdate"%20"$currentTime"~"$currentdate"%20"$oldtime"")
echo -e "the response is: n $Response"

没有得到任何回应?请帮助如何在外壳脚本的 curl URL 中使用系统日期时间/当前日期时间。

看起来是一致的,但不完全确定看起来有什么问题。 您是否尝试过echo响应行以查看它的外观? 尝试将 bash 变量名称括在大括号中并删除字符串中的引号怎么样?

Response=$(curl -X GET -H "Authorization: Basic Token=" "http://targetserver.company.com:8080/v1/organizations/company/environments/environmentname/stats/apis?select=sum(is_error)&timeRange=${currentdate}%20${currentTime}~${currentdate}%20${oldtime}")

最新更新