Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return exit code when host not found #294

Open
ispmarin opened this issue Mar 10, 2019 · 5 comments
Open

Return exit code when host not found #294

ispmarin opened this issue Mar 10, 2019 · 5 comments

Comments

@ispmarin
Copy link

When mtr is used on the command line and an invalid host is passed, mtr raises the message "Failed to resolve host: Name or service not known" but it returns 0, not -1 or any other code. Returning something different from zero when exiting the process with invalid host would make using it with other commands and pipes easier.

@rewolff
Copy link
Collaborator

rewolff commented Mar 10, 2019

Decided this would be a project I could finish in the time before I had to respond to "your're invited for diner, come now" .....
I followed the code, it exits with a failure code when this happens.
I tested the binary, and it returns an error code when this happens. In short: mtr works as you requested. I did test this on the most recent github version. maybe you're using somthing older?

@rewolff rewolff closed this as completed Mar 10, 2019
@ispmarin
Copy link
Author

ispmarin commented Mar 12, 2019

Hi @rewolff, thanks for the feedback. Let me give you an example of what I'm talking about here, to see if helps:

If the command runs successfully, I get return code 0:

`:~$ mtr -C -c 3 terra.com.br
Mtr_Version,Start_Time,Status,Host,Hop,Ip,Loss%,Snt, ,Last,Avg,Best,Wrst,StDev,
MTR.0.87,1552385327,OK,terra.com.br,1,192.168.1.1,0.00,3,0,4.59,5.42,3.64,8.02,2.24
MTR.0.87,1552385327,OK,terra.com.br,2,10.75.128.1,0.00,3,0,11.69,11.53,11.38,11.69,0.00
MTR.0.87,1552385327,OK,terra.com.br,3,c952005a.virtua.com.br,0.00,3,0,12.91,12.55,11.90,12.91,0.00
MTR.0.87,1552385327,OK,terra.com.br,4,c9520008.virtua.com.br,0.00,3,0,27.96,17.79,12.14,27.96,8.80
MTR.0.87,1552385327,OK,terra.com.br,5,c952005a.virtua.com.br,0.00,3,0,14.95,14.27,12.54,15.33,1.22
MTR.0.87,1552385327,OK,terra.com.br,6,embratel-t0-4-0-6-uacc01.cas.embratel.net.br,0.00,3,0,14.04,14.84,14.04,15.26,0.00
MTR.0.87,1552385327,OK,terra.com.br,7,ebt-h0-0-0-0-tcore01.cas.embratel.net.br,0.00,3,0,17.65,15.68,14.06,17.65,1.58
MTR.0.87,1552385327,OK,terra.com.br,8,ebt-b11951-intl01.atl.embratel.net.br,0.00,3,0,129.85,133.75,129.85,137.92,3.94
MTR.0.87,1552385327,OK,terra.com.br,9,ix-et-10-0-2-0.tcore2.a56-atlanta.as6453.net,0.00,3,0,146.52,147.48,146.52,148.38,0.71
MTR.0.87,1552385327,OK,terra.com.br,10,if-ae-14-2.tcore2.mln-miami.as6453.net,0.00,3,0,163.09,163.41,162.75,164.40,0.71
MTR.0.87,1552385327,OK,terra.com.br,11,if-ae-1-2.tcore1.mln-miami.as6453.net,0.00,3,0,163.48,164.81,163.48,166.76,1.58
MTR.0.87,1552385327,OK,terra.com.br,12,63.243.152.142,0.00,3,0,157.73,156.80,155.98,157.73,0.71
MTR.0.87,1552385327,OK,terra.com.br,13,84.16.12.136,0.00,3,0,155.04,154.71,154.22,155.04,0.00
MTR.0.87,1552385327,OK,terra.com.br,14,84.16.9.130,0.00,3,0,154.46,154.55,153.70,155.47,0.71
MTR.0.87,1552385327,OK,terra.com.br,15,66.119.65.193,0.00,3,0,154.49,155.25,154.15,157.12,1.41
MTR.0.87,1552385327,OK,terra.com.br,16,216.177.213.250,0.00,3,0,163.04,164.07,163.04,165.97,1.41
MTR.0.87,1552385327,OK,terra.com.br,17,terra-v-95-srx-mia.tc.terra.com,0.00,3,0,154.07,154.71,154.07,155.19,0.00
MTR.0.87,1552385327,OK,terra.com.br,18,www.terra.com.br,0.00,3,0,163.93,164.68,163.75,166.38,1.22

:~$ echo $?
0
`

So it returns 0, as expected. Let's try now a host that doesn't exist:
`
:~$ mtr -C -c 3 terra.com.br2
Failed to resolve host: Name or service not known

:~$ echo $?
0
`
so this host doesn't exist, but the command still returns 0. Maybe it's something on my version, as I'm using Debian stable:

dpkg -l | grep mtr ii mtr 0.87-1 amd64 Full screen ncurses and X11 traceroute tool
Thanks.

@rewolff
Copy link
Collaborator

rewolff commented Mar 12, 2019

It has something to do with the options you're passing!

getafix:~/mtr> ./mtr -C -c 3 terra.com.br2
./mtr: Failed to resolve host: terra.com.br2: Name or service not known
getafix:~/mtr> echo $?
0
getafix:~/mtr> ./mtr terra.com.br2
./mtr: Failed to resolve host: terra.com.br2: Name or service not known
getafix:~/mtr> echo $?
1
getafix:~/mtr> 

@rewolff rewolff reopened this Mar 12, 2019
@Mike-S-BA
Copy link

Any chance this may get fixed?

@patrykcieszkowski
Copy link

I can confirm that --raw flag causes the mtr to exit with code 0, even on unresolved hostname error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants