shell命令行中的concat字符串

时间:2016-11-16 10:03:12

标签: linux shell

我需要一些帮助才能完成命令行。我需要在一些文件“applications.properties”中获取属性名称“server.port”,然后对“myIp:server.port / health”进行卷曲

我使用以下行获取属性值,并且curl命令获取参数,但我无法在之前和/之后添加IP。

你能帮我完成这个命令行吗?

cat ms-something-*/application.properties | grep server.port | awk '{print $3}' | xargs curl

因此,如果没有最后一个元素“xargs curl”,该行将返回一个端口号列表。但我需要添加ip(例如8.8.8.8)和/ health,以便在"8.8.8.8:server.port/health"上调用curl

2 个答案:

答案 0 :(得分:3)

cat ms-something-*/application.properties | grep server.port | awk '{print "8.8.8.8:"$3"/health"}' | xargs curl
如果我正确理解你的问题,

应该适合你......

答案 1 :(得分:1)

您也可以使用for循环实现此目的。

for port in $(cat ms-something-*/application.properties | grep server.port | awk '{print $3}') ; do 
    curl "8.8.8.8:${port}/health"
done
相关问题