I have this command line, but it's doubling the grep and awk
ifconfig eth1 2> /dev/null | grep "inet " | awk '{gsub("addr:","",$2); print $2 }' ||
ifconfig eth0 2> /dev/null | grep "inet " | awk '{gsub("addr:","",$2); print $2 }'`
I have being trying to shorten this by doing something like,
echo $(ifconfig eth1 2> /dev/null || ifconfig eth0 2> /dev/null) &> grep "inet " |
awk '{gsub("addr:","",$2); print $2 }'
but it returns nothing at all when I am looking to get the IP of server. What is the best way to say get info if on error try this and then pipe it to grep
ip a ||as well in there?ifconfigand useip.