【问题标题】:Unable to pass variable in gremlin query in shell script无法在 shell 脚本的 gremlin 查询中传递变量
【发布时间】:2021-12-18 00:30:07
【问题描述】:

我正在尝试连接到 Neptune DB 并使用 CURL 命令获取顶点详细信息。我有它的shell脚本。但不知何故,可变数据并没有通过它 gremlin 查询。我有一个 Orgid.txt 文件,其中存在tenantid,我的 shell 脚本读取该文件并将其传递给“name”变量

#!/bin/bash

i=1

rm VerticesCount1

while IFS= read -r line
do
name="$line"
#echo "Orgid name is "$i": $name"
curl -X POST https://<Neptune_endpoint>:<port>/gremlin -d '{"gremlin":"g.V().has(\"system.tenantId\",\"$name\").count()"}' >> VerticesCount1
#printf "\n"
echo >> VerticesCount1
((i=i+1))
done < Orgid.txt

【问题讨论】:

    标签: shell curl gremlin amazon-neptune


    【解决方案1】:

    这段代码运行良好。

    while IFS= read -r line
    do
    name="$line"
    #echo "Orgid name is "$i": $name"
    curl -X POST https://<Neptune_endpoint>:<port>/gremlin -d '{"gremlin":"g.V().has(\"system.tenantId\",\"'$name'\").count()"}' >> VerticesCount1
    echo >> VerticesCount1
    done < Orgid.txt
    

    【讨论】:

    【解决方案2】:

    与您的other question 一样,我使用一个简单的数据文件进行了测试,它工作正常。但是,请注意我是如何更改 curl 使用的引号类型的。

    i=1
    
    while IFS= read -r line
    do
    name="$line"
    
    curl -X POST https://mydbcluster.cluster-xxxxxxxxxxxx.us-east-1.neptune.amazonaws.com:8182/gremlin -d \
    "{\"gremlin\":\"g.V().has('code','$name').count()\"}"
    ((i=i+1))
    done < values.txt
    

    产生

    {"requestId":"4e3e80ed-efcb-40a7-b92b-366c6f391d4e","status":{"message":"","code":200,"attributes":{"@type":"g:Map","@value":[]}},"result":{"data":{"@type":"g:List","@value":[{"@type":"g:Int64","@value":1}]},"meta":{"@type":"g:Map","@value":[]}}}{"requestId":"6a269b5b-32f6-49d2-a31d-c51dd52eba29","status":{"message":"","code":200,"attributes":{"@type":"g:Map","@value":[]}},"result":{"data":{"@type":"g:List","@value":[{"@type":"g:Int64","@value":1}]},"meta":{"@type":"g:Map","@value":[]}}}
    

    【讨论】:

    • 非常感谢 Kelvin。对我来说,只需添加“$name”即可。不管怎样,你的回答很有帮助
    • 我看到您未选择接受我的答案并发布了您自己的答案并接受了该答案,这是您的选择,但最好编辑您的答案以解释人们经常看到的变化先到接受的答案。
    • 我还没有实际验证您的解决方案 Kelvin。这个周末我会验证并更新你。
    猜你喜欢
    • 1970-01-01
    • 2021-11-24
    • 2018-07-28
    • 2018-02-26
    • 2014-03-11
    • 2015-09-09
    • 2017-05-24
    • 2015-03-26
    • 1970-01-01
    相关资源
    最近更新 更多