linux shell 获取本机ip 写入文件

本机IP获取

/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"


k8s 获取容器所造node节点的ip

container_net=`ifconfig eth0 |grep "inet" |grep -v "inet6"| awk '{print $2}'|cut -d '.' -f 3`
 
node_ip=`etcdctl --endpoints=https://10.0.13.78:2379,https://10.0.13.80:2379,https://10.0.13.81:2379 --cert-file=/home/yanfa/cert/etcd.pem --key-file=/home/yanfa/cert/etcd-key.pem --ca-file=/home/yanfa/cert/etcd-root-ca.pem get /kube-centos/network/subnets/10.252.${container_net}.0-24 |sed 's/.*"PublicIP":"\([^"]\+\)".*/\1/' `

写入过程 displayip.sh

hostnet=$(/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:")
echo $hostnet >>ipdns.txt
~                                                                                                                  
~                                              

 chmod 755 displayip.sh
运行:./displayip.sh  

发布了159 篇原创文章 · 获赞 177 · 访问量 147万+

猜你喜欢

转载自blog.csdn.net/hanghangaidoudou/article/details/103134889