0
0
Bash Scriptingscripting~15 mins

Network monitoring script in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Network monitoring script
📖 Scenario: You are a system administrator who wants to keep an eye on the network status of a server. You will write a simple Bash script that checks if the server is reachable by pinging it and then reports the result.
🎯 Goal: Build a Bash script that pings a specific IP address or hostname, counts the number of successful responses, and then prints a summary message.
📋 What You'll Learn
Create a variable called target with the IP address or hostname to ping
Create a variable called count to specify how many ping attempts to make
Use the ping command with the -c option to send the specified number of pings to the target
Extract the number of successful ping replies from the ping command output
Print a message showing how many pings succeeded out of the total attempts
💡 Why This Matters
🌍 Real World
Network administrators often need to monitor if servers or devices are reachable to ensure network health.
💼 Career
Knowing how to write simple network monitoring scripts helps in automating routine checks and troubleshooting connectivity issues.
Progress0 / 4 steps
1
Set the target server to ping
Create a variable called target and set it to the IP address 8.8.8.8.
Bash Scripting
Need a hint?

Use target=8.8.8.8 to assign the IP address to the variable.

2
Set the number of ping attempts
Create a variable called count and set it to 4 to specify the number of ping attempts.
Bash Scripting
Need a hint?

Use count=4 to set the number of pings.

3
Ping the target and count successful replies
Use the ping command with -c $count to ping $target. Then use grep and wc -l to count how many lines contain the word bytes from and save this number in a variable called success.
Bash Scripting
Need a hint?

Use command substitution with $(...) to capture the count of successful replies.

4
Print the ping summary
Print a message that says: "Pinged $target $count times: $success successful replies."
Bash Scripting
Need a hint?

Use echo with double quotes to include variables in the message.