如何将bash输出用作变量
我正在创建一个作业,该作业首先启动API检查带有某些参数的子网中的下一个IP是什么。
然后,我想在输出(即IP)上运行“ ping”检查(即IP),然后在同一输出上telnet到端口22 80 3389,
如何将所有curl输出插入到一个变量中,以便我可以继续脚本在指出IP确实“可用”之前,请运行Ping和Telnet检查 - 我在过去的两天中尝试了许多失败的语法:)谢谢。
因此:
#!/bin/bash
curl --stderr -i -H "Accept: application/json" -X POST -d "query=ip" -d "string=$1" -u 'username:password' https://device42.xxxxxxxxx/api/1.0/search/ --insecure | awk '{print "Avaliable",$9,$10,$11}'
[[ -z "$1" ]] && echo "Please Enter IP" ||
API返回此ATM:
available: Yes ip: 10.120.34.11
I am creating a job that would first initiate an API checking what is the next available ip in a subnet with some parameters.
Then i want to run "ping" check on the output (that is an IP), then also telnet to ports 22 80 3389 on the same output,
how can i insert all the CURL output in to a variable so i can continue the script running ping and telnet checks before giving an indication that the ip is really "Available" - i have tried many failed syntaxes in the last 2 days :) thank you.
so:
#!/bin/bash
curl --stderr -i -H "Accept: application/json" -X POST -d "query=ip" -d "string=$1" -u 'username:password' https://device42.xxxxxxxxx/api/1.0/search/ --insecure | awk '{print "Avaliable",$9,$10,$11}'
[[ -z "$1" ]] && echo "Please Enter IP" ||
the api returns this atm:
available: Yes ip: 10.120.34.11
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
curl -stderr -i
无效。您可能想要curl -stderr -i
。尝试在任何外壳中使用命令输出替换`
或其他命令输出替代语法
curl --stderr -i
is invalid. You might wantcurl --stderr - -i
.Try substitution ` with command output in any shell:
Or with another command output substitution syntax