🔹Table Of content :
✅Introduction
✅Key Learnings and Concepts
✅Monitoring System Resources with Commands
✅Using
awk
for Data Processing✅The
while
Loop in Action✅
cut
Command for Precise Data Extraction✅Advanced
vim
Commands
✅Disk Usage Check Script
✅Takeaways from Day 12
Hey DevOps Enthusiasts,
Welcome to Day 12 🚀!
Today, I stepped into the world of system monitoring using advanced shell scripting techniques. From tracking memory usage to writing a script for disk checks, these skills are crucial for ensuring smooth system operations.
✅Key Learnings and Concepts
✅1. Monitoring System Resources with Commands
I explored several essential commands for monitoring system resources, which are key for keeping an eye on the health of a server:
free
: Displays information about RAM usage, helping to keep tabs on memory consumption.df -H
: Shows the disk usage in human-readable form, providing insight into how much space is left on various filesystems.top
: A real-time display of CPU usage, processes, and memory, useful for identifying high-resource processes.
✅2. Using awk
for Data Processing
The awk
command is incredibly useful for separating columns from command output. I used it to extract the filesystem and disk usage columns from the df -H
output:
df -H | awk '{print $5 " " $1}'
✅3. The while
Loop in Action
Loops are essential when automating repetitive tasks. Today, I used a while
loop to iterate over disk usage data and check for critical levels.
while [ condition ];
do
# statements
# commands
done
✅4. cut
Command for Precise Data Extraction
To isolate the percentage of disk space used, I used the cut
command to extract the numerical part of the disk usage:
usage=$(echo $output | awk '{print $1}' | cut -d'%' -f1)
✅5. Advanced vim
Commands
Mastering the text editor vim is key for efficiently managing and editing scripts. Here are some commands I practiced:
:wq
: Save and quit.i
: Enter insert mode.dd
: Delete a line.u
: Undo the last change.
These shortcuts will save a lot of time when working in the terminal.
✅Disk Usage Check Script
As part of my learning, I wrote a script that checks disk usage and alerts if any filesystem exceeds 90% usage. Here’s the code:
#!/bin/bash
df -H | awk '{print $5 " " $1}' | while read output;
do
echo "Disk Detail: $output"
usage=$(echo $output | awk '{print $1}' | cut -d'%' -f1)
file_sys=$(echo $output | awk '{print $2}')
if [ $usage -ge 90 ]; then
echo "CRITICAL for $file_sys"
fi
done
This script loops through the disk usage data, checks each filesystem's percentage used, and flags any critical thresholds.
✅Takeaways from Day 12
System Monitoring: Knowing how to track memory, CPU, and disk usage is essential for server health.
Scripting for Automation: Using commands like
awk
,cut
, and loops, I can now automate resource checks, improving efficiency.Mastering
vim
: Learning the basics ofvim
commands has made editing scripts faster and more productive.
🚀Stay tuned for more updates on my DevOps journey! 📅
Feel free to reach out to me if you have any questions or need any more help. Let’s connect, learn, and succeed together!
Thanks for joining me on Day 12 of this exciting journey. Let’s keep leveling up our skills!
Happy Learning!😊
#90DaysOfDevOps
#Linux #ShellScripting #SystemMonitoring #Automation #DevOpsJourney #TaskAutomation #BashScripting