Complete the code to check disk usage of the root directory.
usage=$(df -h / | tail -1 | awk '[1]')
The awk command extracts the fifth column, which shows the disk usage percentage.
Complete the code to send an alert if disk usage is above 80%.
if [ ${usage%\%} [1] 80 ]; then echo "Disk usage is above 80%!" fi
The -gt operator checks if usage is greater than 80.
Fix the error in the command to get disk usage without the percent sign.
usage=$(df -h / | tail -1 | awk '{print $5}' | [1] '%')
sed 's/%//g' removes all percent signs from the output.
Fill both blanks to create a loop that checks disk usage every 10 seconds and alerts if above 90%.
while true; do usage=$(df -h / | tail -1 | awk '[1]' | sed 's/%//g') if [ $usage [2] 90 ]; then echo "Warning: Disk usage is above 90%!" fi sleep 10 done
The loop extracts the usage percentage with awk '{print $5}' and checks if it is greater than 90 with -gt.
Fill all three blanks to create a script that logs disk usage with timestamp if usage is above 75%.
timestamp=$(date +"[1]") usage=$(df -h / | tail -1 | awk '[2]' | sed 's/%//g') if [ $usage [3] 75 ]; then echo "$timestamp - Disk usage: $usage%" >> /var/log/disk_usage.log fi
The timestamp format is %Y-%m-%d %H:%M:%S, usage is extracted from the fifth column, and the script checks if usage is greater than 75%.