Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在bash中循环执行curl请求列表_Bash_Loops_Curl - Fatal编程技术网

在bash中循环执行curl请求列表

在bash中循环执行curl请求列表,bash,loops,curl,Bash,Loops,Curl,我有一个bash脚本,它发送一个curl请求并显示响应 #!/bin/bash token=$(curl -k -X GET \ 'https://v.mytesting.io/oauth/token?grant_type=password&username=user1&password=123' \ -H 'Authorization: Basic 12345678' \ -H 'Host: v.mytesting.io.io') v=$( jq -r ".acces

我有一个bash脚本,它发送一个curl请求并显示响应

    #!/bin/bash

token=$(curl -k -X GET \
'https://v.mytesting.io/oauth/token?grant_type=password&username=user1&password=123' \
-H 'Authorization: Basic 12345678' \
-H 'Host: v.mytesting.io.io')
v=$( jq -r ".access_token" <<<"$token" )

ts=$(curl -k -X POST \
https://timeseries.mytimeseries.io/v5/time_series/query \
-H 'Authorization: Bearer '"$v" \
-H 'Content-Type: application/json' \
-H 'Host: timeseries.mytimeseries.io' \
-H 'tenant: 123-123-123' \
-d '{"operation" : "raw","responseFormat" : "kairosDB","startTime": "1d-ago","stopTime": "now","tagList" : [ {"tagId" : "V.S.23164117.AVG.10M"}]}')


p=$(jq '.queries[].sample_size, .queries[].results[].name' <<<"$ts")
echo "$p"

#/bin/bash
令牌=$(curl-k-X GET\
'https://v.mytesting.io/oauth/token?grant_type=password&username=user1&password=123' \
-H'授权:基本12345678'\
-H'主机:v.mytesting.io.io')

v=$(jq-r).access_token“您可以使用一个小脚本在标记列表上循环。我对输出格式没有100%的了解。您可以更改“echo”以匹配所需的格式

请注意对引号的细微更改,以允许在正文中展开变量

标记将存储在一个文件中,例如tags.txt

V.S.23164117.AVG.10M
V.S.23164118.AVG.10M
V.S.23164119.AVG.10M
脚本将使用该文件

#! /bin/bash
   # Use user defined list of tags
tags=tags.txt
token=$(curl -k -X GET \
'https://v.mytesting.io/oauth/token?grant_type=password&username=user1&password=123' \
-H 'Authorization: Basic 12345678' \
-H 'Host: v.mytesting.io.io')
v=$( jq -r ".access_token" <<<"$token" )

for tag in $(<$tags) ; do
ts=$(curl -k -X POST \
https://timeseries.mytimeseries.io/v5/time_series/query \
-H 'Authorization: Bearer '"$v" \
-H 'Content-Type: application/json' \
-H 'Host: timeseries.mytimeseries.io' \
-H 'tenant: 123-123-123' \
-d '{"operation" : "raw","responseFormat" : "kairosDB","startTime": "1d-ago","stopTime": "now","tagList" : [ {"tagId" : "'"$tag"'"}]}')

    p=$(jq '.queries[].sample_size, .queries[].results[].name' <<<"$ts")

    echo "$tag $p"
done
!/bin/bash
#使用用户定义的标记列表
tags=tags.txt
令牌=$(curl-k-X GET\
'https://v.mytesting.io/oauth/token?grant_type=password&username=user1&password=123' \
-H'授权:基本12345678'\
-H'主机:v.mytesting.io.io')

v=$(jq-r).access_token“我如何输入标签列表?像这样的标签=$123$234@TammiSantiago稍微更改代码以解决此问题谢谢。我创建了该文件。但我现在运行它时才收到此错误。第13行:标记:没有此类文件或directory@TammiSantiago第13行的打字错误已修复(
tags
替换为
$tags
)。我想你已经找到了这个