fix ips issue and improve it.

pull/999/head
MaYuming 2017-07-06 10:01:00 +08:00
parent f13e04fdb0
commit 4679935a86
2 changed files with 4 additions and 4 deletions

View File

@ -7,10 +7,10 @@ function ips ()
group 'base'
if command -v ifconfig &>/dev/null
then
ifconfig | awk '/inet /{ print $2 }'
ifconfig | grep -B 1 -E "inet "|sed 's/addr://g' | sed 's/://g'|awk '{if (NR%3==1) printf $1 " : "; else if (NR%3==2) {print $2}}'
elif command -v ip &>/dev/null
then
ip addr | grep -oP 'inet \K[\d.]+'
ip addr | grep -B 2 'inet ' | sed 's/://g'|sed 's/\/[0-9]\+//g' | awk '{if(NR%4==1) printf $2 " : "; if(NR%4==3) print $2}'
else
echo "You don't have ifconfig or ip command installed!"
fi

View File

@ -9,10 +9,10 @@ load ../../plugins/available/base.plugin
skip 'ifconfig probably requires sudo on TravisCI'
fi
declare -r localhost='127.0.0.1'
declare -r localhost="lo : 127.0.0.1"
run ips
assert_success
assert_line $localhost
assert_line "$localhost"
}
@test 'plugins base: myip()' {