通过IP地址解析文件-bash
我正在尝试配置MapR群集: IP地址来自/etc/hosts: 我需要的是一个bash脚本,它解析该文件以生成类似于上面的命令。我不太擅长bash,我如何才能做到这一点? 模式如下:通过IP地址解析文件-bash,bash,shell,awk,sed,grep,Bash,Shell,Awk,Sed,Grep,我正在尝试配置MapR群集: IP地址来自/etc/hosts: 我需要的是一个bash脚本,它解析该文件以生成类似于上面的命令。我不太擅长bash,我如何才能做到这一点? 模式如下: /opt/mapr/server/configure.sh -C <all_nodes> -Z <namenode> -HS <namenode> -N MyCluster. 使用此awk: awk '/## vagrant-hostmanager-start/{
/opt/mapr/server/configure.sh -C <all_nodes> -Z <namenode> -HS <namenode> -N MyCluster.
使用此awk:
awk '/## vagrant-hostmanager-start/{
a=1;
next
}
/## vagrant-hostmanager-end/{
exit
}
!a{
next
}
a==1{
a++;
ips=$1;
next
}
a>1{
ips=ips ", " $1
}
$2=="namenode"{
nn=$1
}
END {
printf "/opt/mapr/server/configure.sh -C %s -Z %s -HS %s -N MyCluster\n",
ips, nn, nn
}' /etc/hosts
/opt/mapr/server/configure.sh-C 10.60.63.6、10.144.64.75、10.226.98.24-Z 10.226.98.24-HS 10.226.98.24-N MyCluster
之后我想执行那个命令。。。我该怎么做?我工作不好:root@ip-10-226-98-24:/opt/mapr/server awk'NR==1{ips=$1}NR>1{ips=ips,$1}$2==namenode{nn=$1}END{printf/opt/mapr/server/configure.sh-C%s-Z%s-HS%s-N MyCluster\N,ips,nn,nn}'/etc/hosts/opt/mapr/server/configure.sh-C 127.0.0.0.1,,::1,fe00::0,00::0,ff02,ff2,ff2,ff3::60.63,10.144.64.75,10.226.98.24,-Z 10.226.98.24-HS 10.226.98.24-N MyClustern此选项适用于在vagrant hostmanager开始块和vagrant hostmanager结束块之间有行的原始主机文件。请立即检查我的更新答案,以了解问题中显示的新主机文件。
/opt/mapr/server/configure.sh -C <all_nodes> -Z <namenode> -HS <namenode> -N MyCluster.
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
## vagrant-hostmanager-start
10.60.63.6 dgnode-1 dgnode-1.dg.local
10.144.64.75 dgnode-2 dgnode-2.dg.local
10.226.98.24 namenode namenode.dg.local
## vagrant-hostmanager-end
awk '/## vagrant-hostmanager-start/{
a=1;
next
}
/## vagrant-hostmanager-end/{
exit
}
!a{
next
}
a==1{
a++;
ips=$1;
next
}
a>1{
ips=ips ", " $1
}
$2=="namenode"{
nn=$1
}
END {
printf "/opt/mapr/server/configure.sh -C %s -Z %s -HS %s -N MyCluster\n",
ips, nn, nn
}' /etc/hosts