To add more checks, you can use the same logic we used for the directory and the tool. You can check for file existence, disk space, user identity, or network connectivity.
Here are some "check blocks" you can copy and paste into your health_check.sh script:
1. Check if a File Exists
Check if your script itself or a specific config file exists:
if [ -f "health_check.sh" ]; then
echo "Script File: ${GREEN}EXISTS${RESET}"
else
echo "Script File: ${RED}NOT FOUND${RESET}"
fi
2. Check Disk Usage
This check becomes RED if your disk is more than 90% full:
DISK_USAGE=$(df / | tail -1 | awk '{print $5}' | sed 's/%//')
if [ "$DISK_USAGE" -lt 90 ]; then
echo "Disk Space: ${GREEN}OK ($DISK_USAGE%)${RESET}"
else
echo "Disk Space: ${RED}LOW ($DISK_USAGE%)${RESET}"
fi
3. Check for Internet Connection
This pings Google's DNS briefly to see if you are online:
if ping -c 1 8.8.8.8 &> /dev/null; then
echo "Internet: ${GREEN}CONNECTED${RESET}"
else
echo "Internet: ${RED}OFFLINE${RESET}"
fi
4. Check Current User
In LabEx, the default user is labex. You can verify this identity:
if [ "$USER" == "labex" ]; then
echo "User Identity: ${GREEN}LABEX USER${RESET}"
else
echo "User Identity: ${RED}UNKNOWN USER ($USER)${RESET}"
fi
💡 Practice Tip:
To edit your script again, just type nano health_check.sh, paste these blocks before the echo "Done!" line, save (Ctrl+O), and exit (Ctrl+X).
Moving Forward
By adding these checks, you are effectively building your own System Monitoring Tool, similar to htop but customized for your needs!
As you move from this Guided Lab to your next Challenge, building scripts like this is exactly what will help you master the Linux Skill Tree.
Click Continue in the lab interface to finalize your first successful step into the world of Linux!