Bird
0
0

You want to write a script that pings a server once and checks if it is reachable. Which command correctly pings 192.168.1.1 once and returns success if reachable?

hard📝 Application Q15 of 15
Linux CLI - Networking Commands
You want to write a script that pings a server once and checks if it is reachable. Which command correctly pings 192.168.1.1 once and returns success if reachable?
Aping -c 1 192.168.1.1; echo 'Server reachable'
Bping 192.168.1.1 -c 1 || echo 'Server reachable'
Cping -n 1 192.168.1.1 && echo 'Server reachable'
Dping -c 1 192.168.1.1 && echo 'Server reachable'
Step-by-Step Solution
Solution:
  1. Step 1: Use correct ping syntax for one request

    The -c 1 option sends exactly one ping request in Linux.
  2. Step 2: Use logical AND to echo only if ping succeeds

    The && operator runs the echo command only if ping returns success (reachable).
  3. Step 3: Analyze other options

    ping 192.168.1.1 -c 1 || echo 'Server reachable' uses || which runs echo on failure, not success. ping -n 1 192.168.1.1 && echo 'Server reachable' uses Windows syntax -n. ping -c 1 192.168.1.1; echo 'Server reachable' always echoes regardless of ping result.
  4. Final Answer:

    ping -c 1 192.168.1.1 && echo 'Server reachable' -> Option D
  5. Quick Check:

    Use -c 1 and && for success check [OK]
Quick Trick: Use '-c 1' and '&&' to confirm ping success [OK]
Common Mistakes:
  • Using Windows ping options in Linux
  • Using '||' instead of '&&' for success
  • Echoing message regardless of ping result

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes