简体   繁体   English

bash脚本到windows cmd,使用嵌套命令

[英]bash script to windows cmd, with nested command

I am doing this curl command successfully in bash console to retrieve data from a rest resource : 我在bash控制台中成功执行此curl命令以从其他资源检索数据:

curl -H "Accept: application/json" -H "Content-Type: application/json" -H "X-content: test_content" -H "X-Public: public_key" -H "X-Hash: $(printf "testcompany1" | openssl sha256 -hmac "secret_key" | sed "s/^.* //" | tr -d "\n")" -X GET http://192.168.100.20/rest/v01/customer/csv > /home/user/customer.csv

What I want to do is to use this in a windows cmd shell. 我想要做的是在Windows cmd shell中使用它。 Cygwin and curl is installed. 安装了Cygwin和curl。 So I have tracked it down to this puzzling me, the hmac hashing, done as a nested command in my script using $(command) : 所以我跟踪了这​​个让我感到困惑的,hmac哈希,在我的脚本中使用$(命令)作为嵌套命令完成:

$(printf "testcompany1" | openssl sha256 -hmac "secret_key" | sed "s/^.* //" | tr -d "\n")

How do I get a windows shell cmd recognize this ? 如何让windows shell cmd识别出来? Or is there another smarter approach in windows to get rest data with hmac auth ? 或者是否有另一种更智能的方法在Windows中使用hmac auth获取休息数据?

I split the bash oneliner up i chunks in a batch file like this : 我在一个批处理文件中将bash oneliner拆分为i块,如下所示:

echo off
set content=content
set secret=secret_key
printf %content% | openssl sha256 -hmac %secret% | sed "s/^.* //" | tr -d "\n" > hash.txt
set /p hash=< hash.txt
curl -H "Accept: application/json" -H "Content-Type: application/json" -H "X-content: %content%" -H "X-Public: public_key -H "X-Hash: %hash%" -X GET http://192.168.100.20/rest/v01/customer/csv > out.csv

The printf command was very picky regarding generating the correct hash value, so I send it to a file first, and back again. printf命令对于生成正确的哈希值非常挑剔,因此我首先将其发送到文件,然后再返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM