卷曲bash脚本被截断/合并

时间:2019-10-11 11:28:54

标签: linux bash curl

我的目标是使bash脚本启动以从WEB API获取令牌并将该令牌解析为post命令,然后该命令将在该WEB API上创建一个新帐户(基于用户输入)。它成功获得了令牌,但是当我在POST命令中引用该变量时,它要么将其切断,要么将其合并到选项卡中。有人见过这种情况吗?

我读过一个类似的问题,其中的问题是内容标题,我已删除了该问题,但尚未解决问题。

警告...我是学习者,所以我的代码不是最好的!

我的bash脚本:

#!/bin/bash

curl --insecure -X POST \
  https://192.168.XX.XXX:8443/application/token \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/xml' \
  -H 'Host: 192.168.XX.XX:8443' \
  -H 'cache-control: no-cache' \
  -H 'client-key: 123' \
  -H 'client-name: 1234' \
  -H 'client-secret: 123456' \
  -H 'grant_type: OAuth' \
  -d '<request>
    <username>johndoe</username>
    <password>secret</password>
</request>' > tokenNewAcc.xml

grep 'access_token' tokenNewAcc.xml | sed 's/.*://' | sed s/,// |  tr -d '"' > /home/oracle/tokenNewAcc.txt

rm tokenNewAcc.xml

value=`cat /home/oracle/tokenNewAcc.txt`

MYVAR=`cat /home/oracle/testaccounts.txt`

ID=`cut -d' ' -f1  /home/oracle/testaccounts.txt`
FNAME=`cut -d' ' -f2  /home/oracle/testaccounts.txt`
LNAME=`cut -d' ' -f3 /home/oracle/testaccounts.txt`
EMAIL=`cut -d' ' -f4  /home/oracle/testaccounts.txt`L
\

curl -k -X POST \
  https://192.168.XX.XXX:8443/application/accounts \
  -H 'Accept: */*' \
  -H 'Content-Type: application/xml' \
  -H 'Host: 192.168.XX.XXX:8443' \
  -H "auth: "$value"" \
  -H 'cache-control: no-cache' \
  -d '<request>
<userid'$ID'</userid>
<firstname>'$FNAME'</firstname>
<lastname>'$LNAME'</lastname>
<email>'$EMAIL'</email>
</request>'


OUTPUT of POST where it has trouble:

curl -k -X POST https://192.168.36.XXX:8443/cloudminder/accounts -H 'Accept: */*' -H 'Content-Type: application/xml' -H 'Host: 192.168.36.1' -H 'cache-control: no-cache' -d '<request>ad9f23295b6
<useridconnectortest</userid>
<firstname>conn</firstname>
<lastname>connect</lastname>
<email>connectorL</email>
</request>'

如您所见,主机URL被切断,令牌的开头(ad9f23295b6)合并到请求中。

0 个答案:

没有答案