#!/bin/bash
p=`pwd`
file=$p/localip.txt
if [ -f "$file" ];then
rm $file
touch $file
fi
#Ubuntu系统
if [[ -f /etc/debian_version ]]
then
for IP in $(ip a | grep inet | grep -v 127.0.0.1 | grep -v inet6 | awk '{print $2}' | cut -d "/" -f1)
do
echo ${IP} >> localip.txt
done
#centos系统
else [[ -f /etc/centos-release ]]
for IP in $(ip a | grep inet | grep -v 127.0.0.1 | grep -v inet6 | awk '{pri nt $2}' | cut -d "/" -f1)
do
echo ${IP} >> localip.txt
done
fi