0
0
Bash Scriptingscripting~10 mins

Network monitoring script in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to ping a host once and check if it is reachable.

Bash Scripting
ping -c [1] 8.8.8.8
Drag options to blanks, or click blank then click option'
A1
B5
C0
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or no count sends unlimited pings.
Using too many pings delays the check.
2fill in blank
medium

Complete the code to store the ping command's exit status in a variable.

Bash Scripting
ping -c 1 8.8.8.8
status=[1]
Drag options to blanks, or click blank then click option'
A$!
B$?
C$#
D$$
Attempts:
3 left
💡 Hint
Common Mistakes
Using $! which holds the last background process ID.
Using $$ which holds the current script's PID.
3fill in blank
hard

Fix the error in the if statement to check if the ping was successful.

Bash Scripting
if [ [1] -eq 0 ]; then
  echo "Host is reachable"
else
  echo "Host is unreachable"
fi
Drag options to blanks, or click blank then click option'
Astatus
B$?status
C$status
Dstatus$
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable name without $ causes string comparison, not numeric.
Adding $ in wrong place causes syntax error.
4fill in blank
hard

Fill both blanks to create a loop that pings a host 3 times and prints the result each time.

Bash Scripting
for i in [1]; do
  ping -c 1 8.8.8.8
  result=$?
  if [ $result [2] 0 ]; then
    echo "Ping $i: Success"
  else
    echo "Ping $i: Fail"
  fi
done
Drag options to blanks, or click blank then click option'
A"1 2 3"
B==
C-eq
D1 2 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers makes the loop treat it as one string.
Using == instead of -eq causes numeric comparison errors.
5fill in blank
hard

Fill all three blanks to create a script that logs ping results with timestamps to a file.

Bash Scripting
for i in [1]; do
  ping -c 1 8.8.8.8 > /dev/null
  status=$?
  echo "$(date [2]) Ping $i: $[3]" >> ping_log.txt
done
Drag options to blanks, or click blank then click option'
A1 2 3 4 5
B"+%Y-%m-%d %H:%M:%S"
Cstatus
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable name for status.
Not quoting the date format string.
Using too few or too many loop iterations.