4 ms·
getting an IP is still pretty ugly, somehow: ip address show dev eno1|grep 'inet '|cut '-d ' -f6 But I wouldn't call it unreliable. The cut is the only real
by qwertyuiop924 10y ago
getting an IP is still pretty ugly, somehow:
ip address show dev eno1|grep 'inet '|cut '-d ' -f6
But I wouldn't call it unreliable. The cut is the only really nasty bit.
Changing your fstab is easy with a little awk:
$2=="/tmp"{$4=$4 ",nosuid"}
{print $0}
Given, it won't remove contradicting options...
- jjnoakes 10y agoAnd either the "ip" command can never change how it formats its output, or your script with that command will break some day.
- qwertyuiop924 10y ago...Which is why I said it was ugly. The grep probably won't break, the cut is more likely to. This is in part because the 'ip' command isn't very well designed. A better solution I found is ip addr show wlan0 | grep -Po 'inet \K[\d.]+' Which is less likely to break. If your system supports it, hostname -I Works great. However, this seems to be an ubuntuism, and it doesn't work on my system.
- vasilia 10y agoip addr show eth0 | awk '/inet/ { print $2 }' Will be better ;) 'inet[::space::] ' not working with ipv6 addresses.
- qwertyuiop924 10y agoI though there was a specific desire for ipv4 addrs. That's why the space was there.
- viraptor 10y agoIt's unreliable, because you don't know where you'll find 'inet ' or what's the specific spacing of the output. Also, that's not the ip, because you've still got the cidr attached. And no, fstab is not easy either. For example it fails for: # /tmp has option_blah in order to ... changing it to: # /tmp has option_blah,nosuid in order to ... Confusing the next person to look at the well intended comment. It's no impossible to implement fairly reliably, it's not going to take days to do, but you're likely make mistakes. And in both cases you're spawning extra processes instead of just getting the information you need. PS. also slightly annoying is that everyone is so concerned about the text processing part that barely anyone checks what the tool itself can do. (ip -4 -o a s dev eno1 | awk '{print $4}')
- qwertyuiop924 10y ago>PS. also slightly annoying is that everyone is so concerned about the text processing part that barely anyone checks what the tool itself can do. (ip -4 -o a s dev eno1 | awk '{print $4}') Actually, I spend a while digging through the manpage to try and find this. ip has awful docs. As for the comment problem, yeah, not optimal.
- qwertyuiop924 10y agoOh, I forgot: the comment you showed wouldn't trigger my AWK script. Read it more carefully.
- viraptor 10y agoYes it will. If you mean the $2 part, the comment character takes the place of $1. Or did you mean something else? (either way, I tested it before posting)
- qwertyuiop924 10y agoNope, you're right. I just miscounted. You could always add && $1 != "#" To fix this, though.