0
0
Bash Scriptingscripting~30 mins

Script testing strategies in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Script Testing Strategies
📖 Scenario: You are a system administrator who wrote a small bash script to check disk usage on your server. You want to make sure your script works correctly before using it in daily monitoring.
🎯 Goal: Build a simple bash script that checks disk usage and test it with different inputs to ensure it works as expected.
📋 What You'll Learn
Create a bash script variable with a sample disk usage value
Add a threshold variable to compare disk usage
Write a conditional statement to check if disk usage exceeds the threshold
Print a message indicating if disk usage is safe or critical
💡 Why This Matters
🌍 Real World
System administrators often write scripts to monitor server health. Testing these scripts ensures they behave correctly before deployment.
💼 Career
Knowing how to write and test bash scripts is essential for roles in system administration, DevOps, and automation engineering.
Progress0 / 4 steps
1
Create a variable with disk usage value
Create a bash variable called disk_usage and set it to the value 75 representing disk usage percentage.
Bash Scripting
Need a hint?

Use variable_name=value syntax without spaces around the equals sign.

2
Add a threshold variable
Create a bash variable called threshold and set it to 80 to represent the critical disk usage percentage.
Bash Scripting
Need a hint?

Remember to use the same syntax as before for variables.

3
Write a conditional to check disk usage
Write an if statement that compares disk_usage with threshold. If disk_usage is greater than or equal to threshold, set a variable status to "Critical". Otherwise, set status to "Safe".
Bash Scripting
Need a hint?

Use [ "$disk_usage" -ge "$threshold" ] for numeric comparison in bash.

4
Print the disk usage status
Write a echo command to print the message: Disk usage status: followed by the value of the status variable.
Bash Scripting
Need a hint?

Use echo "Disk usage status: $status" to print the message.