0
0
Bash Scriptingscripting~10 mins

Disk space monitoring script in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check disk usage of the root directory.

Bash Scripting
usage=$(df -h / | tail -1 | awk '[1]')
Drag options to blanks, or click blank then click option'
A{print $3}
B{print $1}
C{print $5}
D{print $6}
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting the wrong column number with awk.
Forgetting to use tail to get the last line.
2fill in blank
medium

Complete the code to send an alert if disk usage is above 80%.

Bash Scripting
if [ ${usage%\%} [1] 80 ]; then
  echo "Disk usage is above 80%!" 
fi
Drag options to blanks, or click blank then click option'
A-lt
B-gt
C-eq
D-le
Attempts:
3 left
💡 Hint
Common Mistakes
Using string comparison operators instead of numeric.
Not removing the percent sign before comparison.
3fill in blank
hard

Fix the error in the command to get disk usage without the percent sign.

Bash Scripting
usage=$(df -h / | tail -1 | awk '{print $5}' | [1] '%')
Drag options to blanks, or click blank then click option'
Aawk '{gsub("%", ""); print}'
Bgrep -v '%'
Ccut -d '%' -f 1
Dsed 's/%//g'
Attempts:
3 left
💡 Hint
Common Mistakes
Using grep which filters lines instead of removing characters.
Using cut incorrectly with delimiters.
4fill in blank
hard

Fill both blanks to create a loop that checks disk usage every 10 seconds and alerts if above 90%.

Bash Scripting
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
Drag options to blanks, or click blank then click option'
A{print $5}
B-lt
C-gt
D{print $4}
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column number in awk.
Using the wrong comparison operator.
5fill in blank
hard

Fill all three blanks to create a script that logs disk usage with timestamp if usage is above 75%.

Bash Scripting
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
Drag options to blanks, or click blank then click option'
A%Y-%m-%d %H:%M:%S
B{print $5}
C-gt
D{print $3}
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong date format string.
Extracting wrong column for usage.
Using incorrect comparison operator.