在shell中,使用Here Document方式将文本重定向到文件,格式如下:

 



(
cat << EOF
要写的文本
EOF
) > 目标文件


 

示例test.sh:

 



#! /bin/sh
(
cat << EOF
{
"warehouse":"$1",
"ipaddr": "$2",
"bindaddr": "$2:9995",
"repopath": "./repo/",
"kafka": "100.69.168.38:9095",
"topic": "AgentHeartBeat",
"partition": "1"
}
EOF
) > agent/conf/agent.conf.json1


 


 


 

执行"test.sh ys 192.168.1.80"的结果:



[root@lvs00 monitor-agent]# cat agent/conf/agent.conf.json1
{
"warehouse":"ys",
"ipaddr": "192.168.1.80",
"bindaddr": "192.168.1.80:9995",
"repopath": "./repo/",
"kafka": "192.168.1.2:9095",
"topic": "AgentHeartBeat",
"partition": "1"
}
[root@lvs00 monitor-agent]#