ping: show only results
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Is it possible to only show the amount of milliseconds when pinging instead of the whole result page?
I want to check if my servers are online, so I want to return "OK xyz ms" or "FAIL". I am currently doing this like so:
#!/bin/sh
ergebnis=$(ping -qc1 google.com)
ok=$?
avg=$(echo -e "$ergebnis" | tail -n1 | awk 'print $4' | cut -f 2 -d "/")
if [ $ok -eq 0 ]
then
echo "OK $avg ms"
else
echo "FAIL"
fi
However, this uses quite a few pipes and since I am running this command pretty often to monitor my servers, I am wondering if there is a "smarter" approach. I am also afraid my pipes might not work properly when the ping command failes.
shell ping
add a comment |Â
up vote
1
down vote
favorite
Is it possible to only show the amount of milliseconds when pinging instead of the whole result page?
I want to check if my servers are online, so I want to return "OK xyz ms" or "FAIL". I am currently doing this like so:
#!/bin/sh
ergebnis=$(ping -qc1 google.com)
ok=$?
avg=$(echo -e "$ergebnis" | tail -n1 | awk 'print $4' | cut -f 2 -d "/")
if [ $ok -eq 0 ]
then
echo "OK $avg ms"
else
echo "FAIL"
fi
However, this uses quite a few pipes and since I am running this command pretty often to monitor my servers, I am wondering if there is a "smarter" approach. I am also afraid my pipes might not work properly when the ping command failes.
shell ping
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Is it possible to only show the amount of milliseconds when pinging instead of the whole result page?
I want to check if my servers are online, so I want to return "OK xyz ms" or "FAIL". I am currently doing this like so:
#!/bin/sh
ergebnis=$(ping -qc1 google.com)
ok=$?
avg=$(echo -e "$ergebnis" | tail -n1 | awk 'print $4' | cut -f 2 -d "/")
if [ $ok -eq 0 ]
then
echo "OK $avg ms"
else
echo "FAIL"
fi
However, this uses quite a few pipes and since I am running this command pretty often to monitor my servers, I am wondering if there is a "smarter" approach. I am also afraid my pipes might not work properly when the ping command failes.
shell ping
Is it possible to only show the amount of milliseconds when pinging instead of the whole result page?
I want to check if my servers are online, so I want to return "OK xyz ms" or "FAIL". I am currently doing this like so:
#!/bin/sh
ergebnis=$(ping -qc1 google.com)
ok=$?
avg=$(echo -e "$ergebnis" | tail -n1 | awk 'print $4' | cut -f 2 -d "/")
if [ $ok -eq 0 ]
then
echo "OK $avg ms"
else
echo "FAIL"
fi
However, this uses quite a few pipes and since I am running this command pretty often to monitor my servers, I am wondering if there is a "smarter" approach. I am also afraid my pipes might not work properly when the ping command failes.
shell ping
asked Dec 6 '17 at 12:54
mfnalex
1167
1167
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
3
down vote
accepted
Another awk
variation:
ping -qc1 google.com 2>&1 | awk -F'/' 'END print (/^rtt/? "OK "$5" ms":"FAIL") '
-F'/'
- treat slash/
as field separator
Example output:
OK 47.090 ms
1
Nice, relying on the last line being kept forEND
processing!
â Stephen Kitt
Dec 6 '17 at 13:38
@StephenKitt, thanks ...
â RomanPerekhrest
Dec 6 '17 at 14:05
Thanks, seems to be the nicest solution. Although it was not faster than my way, it seems more elegant.
â mfnalex
Dec 8 '17 at 15:05
add a comment |Â
up vote
3
down vote
ThereâÂÂs not much you can do with ping
itself, but you can do all the processing in AWK, reducing the number of pipes, processes etc.:
ping -qc1 google.com 2>&1 | awk -F/ '/^rtt/ printf "OK %.2f msn", $5; ok = 1 END if (!ok) print "FAIL" '
Thanks, that is definitely better than my solution.
â mfnalex
Dec 6 '17 at 13:34
add a comment |Â
up vote
0
down vote
If you are not too concerned about the exact error message then how about
ping google.com | grep -Po "time.*"
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Another awk
variation:
ping -qc1 google.com 2>&1 | awk -F'/' 'END print (/^rtt/? "OK "$5" ms":"FAIL") '
-F'/'
- treat slash/
as field separator
Example output:
OK 47.090 ms
1
Nice, relying on the last line being kept forEND
processing!
â Stephen Kitt
Dec 6 '17 at 13:38
@StephenKitt, thanks ...
â RomanPerekhrest
Dec 6 '17 at 14:05
Thanks, seems to be the nicest solution. Although it was not faster than my way, it seems more elegant.
â mfnalex
Dec 8 '17 at 15:05
add a comment |Â
up vote
3
down vote
accepted
Another awk
variation:
ping -qc1 google.com 2>&1 | awk -F'/' 'END print (/^rtt/? "OK "$5" ms":"FAIL") '
-F'/'
- treat slash/
as field separator
Example output:
OK 47.090 ms
1
Nice, relying on the last line being kept forEND
processing!
â Stephen Kitt
Dec 6 '17 at 13:38
@StephenKitt, thanks ...
â RomanPerekhrest
Dec 6 '17 at 14:05
Thanks, seems to be the nicest solution. Although it was not faster than my way, it seems more elegant.
â mfnalex
Dec 8 '17 at 15:05
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Another awk
variation:
ping -qc1 google.com 2>&1 | awk -F'/' 'END print (/^rtt/? "OK "$5" ms":"FAIL") '
-F'/'
- treat slash/
as field separator
Example output:
OK 47.090 ms
Another awk
variation:
ping -qc1 google.com 2>&1 | awk -F'/' 'END print (/^rtt/? "OK "$5" ms":"FAIL") '
-F'/'
- treat slash/
as field separator
Example output:
OK 47.090 ms
edited Dec 6 '17 at 13:38
Stephen Kitt
143k22310374
143k22310374
answered Dec 6 '17 at 13:32
RomanPerekhrest
22.4k12145
22.4k12145
1
Nice, relying on the last line being kept forEND
processing!
â Stephen Kitt
Dec 6 '17 at 13:38
@StephenKitt, thanks ...
â RomanPerekhrest
Dec 6 '17 at 14:05
Thanks, seems to be the nicest solution. Although it was not faster than my way, it seems more elegant.
â mfnalex
Dec 8 '17 at 15:05
add a comment |Â
1
Nice, relying on the last line being kept forEND
processing!
â Stephen Kitt
Dec 6 '17 at 13:38
@StephenKitt, thanks ...
â RomanPerekhrest
Dec 6 '17 at 14:05
Thanks, seems to be the nicest solution. Although it was not faster than my way, it seems more elegant.
â mfnalex
Dec 8 '17 at 15:05
1
1
Nice, relying on the last line being kept for
END
processing!â Stephen Kitt
Dec 6 '17 at 13:38
Nice, relying on the last line being kept for
END
processing!â Stephen Kitt
Dec 6 '17 at 13:38
@StephenKitt, thanks ...
â RomanPerekhrest
Dec 6 '17 at 14:05
@StephenKitt, thanks ...
â RomanPerekhrest
Dec 6 '17 at 14:05
Thanks, seems to be the nicest solution. Although it was not faster than my way, it seems more elegant.
â mfnalex
Dec 8 '17 at 15:05
Thanks, seems to be the nicest solution. Although it was not faster than my way, it seems more elegant.
â mfnalex
Dec 8 '17 at 15:05
add a comment |Â
up vote
3
down vote
ThereâÂÂs not much you can do with ping
itself, but you can do all the processing in AWK, reducing the number of pipes, processes etc.:
ping -qc1 google.com 2>&1 | awk -F/ '/^rtt/ printf "OK %.2f msn", $5; ok = 1 END if (!ok) print "FAIL" '
Thanks, that is definitely better than my solution.
â mfnalex
Dec 6 '17 at 13:34
add a comment |Â
up vote
3
down vote
ThereâÂÂs not much you can do with ping
itself, but you can do all the processing in AWK, reducing the number of pipes, processes etc.:
ping -qc1 google.com 2>&1 | awk -F/ '/^rtt/ printf "OK %.2f msn", $5; ok = 1 END if (!ok) print "FAIL" '
Thanks, that is definitely better than my solution.
â mfnalex
Dec 6 '17 at 13:34
add a comment |Â
up vote
3
down vote
up vote
3
down vote
ThereâÂÂs not much you can do with ping
itself, but you can do all the processing in AWK, reducing the number of pipes, processes etc.:
ping -qc1 google.com 2>&1 | awk -F/ '/^rtt/ printf "OK %.2f msn", $5; ok = 1 END if (!ok) print "FAIL" '
ThereâÂÂs not much you can do with ping
itself, but you can do all the processing in AWK, reducing the number of pipes, processes etc.:
ping -qc1 google.com 2>&1 | awk -F/ '/^rtt/ printf "OK %.2f msn", $5; ok = 1 END if (!ok) print "FAIL" '
edited Dec 6 '17 at 13:14
answered Dec 6 '17 at 13:03
Stephen Kitt
143k22310374
143k22310374
Thanks, that is definitely better than my solution.
â mfnalex
Dec 6 '17 at 13:34
add a comment |Â
Thanks, that is definitely better than my solution.
â mfnalex
Dec 6 '17 at 13:34
Thanks, that is definitely better than my solution.
â mfnalex
Dec 6 '17 at 13:34
Thanks, that is definitely better than my solution.
â mfnalex
Dec 6 '17 at 13:34
add a comment |Â
up vote
0
down vote
If you are not too concerned about the exact error message then how about
ping google.com | grep -Po "time.*"
add a comment |Â
up vote
0
down vote
If you are not too concerned about the exact error message then how about
ping google.com | grep -Po "time.*"
add a comment |Â
up vote
0
down vote
up vote
0
down vote
If you are not too concerned about the exact error message then how about
ping google.com | grep -Po "time.*"
If you are not too concerned about the exact error message then how about
ping google.com | grep -Po "time.*"
answered Dec 6 '17 at 13:28
bu5hman
1,164214
1,164214
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409203%2fping-show-only-results%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password