OutsideIT / FireMotD

:fire: Fire Framework Linux MoTD Generator :fire:
https://outsideit.net/firemotd
GNU General Public License v3.0
174 stars 45 forks source link

Fedora 27 - Unable to parse ip. Please debug #99

Closed zeleanon closed 6 years ago

zeleanon commented 6 years ago

IP not displayed properly on Fedora 27

Enhancement Request

When using FireMotD on Fedora 27, the ip address is not displayed but instead the error message in the title. This appears to be due to a newer version of "ip", which on my machine shows uid at the end of line instead of the IP address, making it not match the criteria and hence it displays the error.

A change on line 221 of /usr/local/bin/FireMotD seems to fix that. HostIp="$(${IpPath} route get 8.8.8.8 | head -1 | cut -d" " -f7)"

I've substituted -f7 in place of the -f8 in cut. After running FireMotD -S, it appears to work. I'm not sure if anyone wants to use this to make a Fedora 27 fork, but I don't have the knowledge or time right now. Just thought I'd share my solution. Thanks.

Expected Behavior: Display IP

Actual Behavior: Unable to parse ip. Please debug.

How to reproduce Behavior: Install on Fedora 27, run script

zeleanon commented 6 years ago

Actually, as a side note, this appears to be an issue on Cent as well. If you run the command in shell, ip route get 8.8.8.8 | head -1 | cut -d" " -f8, you'll get nothing on my up to date CentOS box. f7 gets the ip. The only reason it works on Cent is because the other command, ip route get 8.8.8.8 | head -1 | awk -F' ' '{print $(NF)}' does work. On Fedora, it returns my uid. Not sure how to fix that with awk though, so I fixed cut.

dimon222 commented 6 years ago

If this is only about ip version, then we can theoretically look after implementing something similar to free adjustment in here

Do you mind mentioning versions of your ip tool on both of your OS? Just type ip -V

I checked on my Debian machines, and all got so far: iproute2-ss140804 This case is working me: HostIp="$(${IpPath} route get 8.8.8.8 | head -1 | awk -F' ' '{print $(NF)}')"

zeleanon commented 6 years ago

CentOS 7: iproute2-ss130716 Output of ip route get 8.8.8.8 | head -1:

8.8.8.8 via 192.168.0.1 dev kbem1 src 192.168.0.100

Fedora 27: iproute2-ss180129 Output:

8.8.8.8 via 192.168.0.1 dev enp2s0 src 192.168.0.127 uid 1001

zeleanon commented 6 years ago

Output with awk version:

CentOS: 192.168.0.100

Fedora 27: 1001 (my uid)

IamUSER commented 6 years ago

This seems to be a better fit on Kali/Debian with iproute2-ss180402 HostIp="$(${IpPath} route get 8.8.8.8 | head -1 | cut -d" " -f7)"

This gives me "uid" as a result. HostIp="$(${IpPath} route get 8.8.8.8 | head -1 | cut -d" " -f8)"

Just adding to the thread since I encountered the issue on my RPi project.

IamUSER commented 6 years ago

I'm also a fan of this option for the public IP. HostIp="$(curl -s ipecho.net/plain; echo)"

willemdh commented 6 years ago

@IamUSER It's not always ideal to check ip through external website. I prefer the ip route option. I did a fix which hopefully makes it more stable for all distributions.

@zeleanon Please let me know if https://github.com/OutsideIT/FireMotD/pull/105 works for you.

willemdh commented 6 years ago

I'm closing this issue, please try latest version. If #108 doesn't work, met me know and I'll reopen.