0
0
Bash Scriptingscripting~15 mins

Why network scripts automate connectivity tasks in Bash Scripting - See It in Action

Choose your learning style9 modes available
Why Network Scripts Automate Connectivity Tasks
📖 Scenario: You are a network technician who needs to check if several important servers are reachable. Doing this manually every time is slow and boring. Automating this task with a script saves time and avoids mistakes.
🎯 Goal: Build a simple Bash script that checks if a list of servers are reachable by pinging them. The script will automate the connectivity check and print the results.
📋 What You'll Learn
Create a Bash array with exact server names
Create a variable for the ping count
Use a for loop to ping each server using the ping count variable
Print whether each server is reachable or not
💡 Why This Matters
🌍 Real World
Network administrators often need to check if servers or devices are online. Automating this with scripts saves time and reduces errors.
💼 Career
Knowing how to write simple network scripts is useful for IT support, system administrators, and network engineers to monitor and troubleshoot connectivity.
Progress0 / 4 steps
1
Create the server list
Create a Bash array called servers with these exact entries: "google.com", "github.com", and "example.com".
Bash Scripting
Need a hint?

Use parentheses and quotes to create a Bash array.

2
Set the ping count
Create a variable called ping_count and set it to 2 to specify how many ping packets to send.
Bash Scripting
Need a hint?

Just assign the number 2 to the variable ping_count.

3
Ping each server
Use a for loop with the variable server to iterate over servers. Inside the loop, ping each server using ping -c $ping_count $server and check if the ping was successful using $?.
Bash Scripting
Need a hint?

Use the ping command with -c option and check the exit status with $?.

4
Display the results
Run the script so it prints whether each server is reachable or not. The output should show exactly these lines for each server: google.com is reachable, github.com is reachable, and example.com is reachable (or not reachable if ping fails).
Bash Scripting
Need a hint?

Just run the script. The echo commands inside the loop print the results.