在windows10 下使用PowerShell执行
- 循环调用job 时间间隔以一个小时为准。
说明:
access-token 为系统token
#!/bin/bash
#以小时循环
#sh ./x.sh 2020110100 2020120100
stime=$1
etime=$2
arr=('job1' 'job2' 'job3')
while :
do
echo $stime
startTime=$(date '+%Y-%m-%d %H:%M:%S' --date="${stime:0:8} ${stime:8:2} 0hour")
endTime=$(date '+%Y-%m-%d %H:%M:%S' --date="${stime:0:8} ${stime:8:2} 1hour")
echo "startTime:"$startTime
echo "endTime:"$endTime
for item in ${arr[*]}
do
#url传参不能有空格 需使用替换
url="'http://xxx/xxxJob?beginDate="${startTime/ /%20}"&endDate="${endTime/ /%20}"&jobName="$item"'"
echo ""
echo " --------------- start GET ------------------"
echo "GET $url"
curl --header 'access-token: access-token' \
--header 'Authorization: Bearer access-token' \
--location \
--request GET "http://xxx/xxxJob?beginDate="${startTime/ /%20}"&endDate="${endTime/ /%20}"&jobName="$item
echo " --------------- end GET ------------------"
echo ""
done
sleep 1
stime=$(date -d "${stime:0:8} ${stime:8:2} 1hour" +%Y%m%d%H)
if [[ $stime -gt $etime ]]
then
break
fi
done
运行 效果
--------------- start GET ------------------
GET 'http://xxx/xxxJob?beginDate=2020-12-10%2004:00:00&endDate=2020-12-10%2005:00:00&jobName=job1'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 18 0 18 0 0 9 0 --:--:-- 0:00:01 --:--:-- 9{"code":"SUCCESS"}
--------------- end GET ------------------
- 循环调用job 时间间隔以一天为准。
#!/usr/bin/env bash
# ./testday.sh 2020-12-01 2020-10-15
stime="$1"
etime="$2"
tempdate=`date -d "-0 day $stime" +%Y%m%d`
enddate=`date -d "-0 day $etime" +%Y%m%d`
echo "###############Start#####################"
echo 'startTime: '$tempdate
echo 'endTime: '$enddate
while [[ $tempdate -gt $enddate ]]
do
startTime=`date -d "${tempdate} -1day" +%Y-%m-%d`
endTime=`date -d "${tempdate} 0day" +%Y-%m-%d`
#执行代码
#...
sleep 1
tempdate=`date -d "${tempdate} -1day" +%Y%m%d`
done
echo "###############end#####################"
网友评论