Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tasks/module_4/task-1/.bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source ./disk_space_monitor.sh
13 changes: 13 additions & 0 deletions tasks/module_4/task-1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# PR Instructions

## Task 1

In the first task, a name conflict occurred, so you can find a folder named `task-1` (instead of `task_1`) within the `tasks` directory, which contains a submodule `module_4`.

## Task 2

For the second task, you need to update your `.bashrc` file to match the one in this PR and specify the correct path in the `disk_space_monitor.sh` file.

## Task 3

To check the third task, simply run the script named `count_files.sh`.
4 changes: 4 additions & 0 deletions tasks/module_4/task-1/count_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

count=$(find . -type f | wc -l)
echo "Total number of files is $count"
28 changes: 28 additions & 0 deletions tasks/module_4/task-1/disk_space_monitor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
if [ -z "$DISK_THRESHOLD" ]; then
read -p "Enter the threshold value for disk space monitoring (default is 10%): " threshold
threshold=${threshold:-10}
export DISK_THRESHOLD="$threshold"
fi

DEFAULT_PS1="$PS1"
WARNING_ADDED=false
PREVIOUS_USED_PERCENTAGE=0

check_disk_space() {
user_home="$HOME"
df_output=$(df -h "$user_home")
used_percentage=$(echo "$df_output" | awk 'NR == 2 {print $5}' | sed 's/%//')

if [ "$used_percentage" -ge "$DISK_THRESHOLD" ] && [ "$WARNING_ADDED" = false ]; then
PS1="\[\e[31m\][Warning: $used_percentage% space used] \[\e[0m\]$DEFAULT_PS1"
WARNING_ADDED=true
elif [ "$used_percentage" -lt "$DISK_THRESHOLD" ] && [ "$WARNING_ADDED" = true ]; then
PS1="$DEFAULT_PS1"
WARNING_ADDED=false
fi

PREVIOUS_USED_PERCENTAGE="$used_percentage"
}

PROMPT_COMMAND="check_disk_space"
PS1="$DEFAULT_PS1"