BASH get ip from ifconfig ( and grep hostname from /etc/hosts by IP)
#!/bin/bash
IP=`/usr/sbin/ip addr show dev eth0| grep -v inet6| awk ' !/127.0.0.1/ && /inet/ { gsub(/\/.*/, "", $2); print $2 }'`
grep $IP /etc/hosts | sed -r s/$IP\\s\\t//
IP=`/usr/sbin/ip addr show dev eth0| grep -v inet6| awk ' !/127.0.0.1/ && /inet/ { gsub(/\/.*/, "", $2); print $2 }'`
grep $IP /etc/hosts | sed -r s/$IP\\s\\t//
Total Comments 0