From 60bfb2c6fdc460a2a76a5ff1e9ef45feffa00ce3 Mon Sep 17 00:00:00 2001 From: momodu abdulsalam Date: Wed, 15 Apr 2026 09:02:07 +0100 Subject: [PATCH] feat: complete bash toolkit assigment --- READ.me | 0 logs/process_monitor.log | 1 + logs/system_report_2026-04-14.log | 32 +++++++++++++++++++++++ logs/user_info.log | 1 + run_all.sh | 31 ++++++++++++++++++++++ scripts/backup.sh | 28 ++++++++++++++++++++ scripts/file_manager.sh | 43 +++++++++++++++++++++++++++++++ scripts/process_monitor.sh | 17 ++++++++++++ scripts/system_check.sh | 26 +++++++++++++++++++ scripts/user_info.sh | 24 +++++++++++++++++ 10 files changed, 203 insertions(+) create mode 100644 READ.me create mode 100644 logs/process_monitor.log create mode 100644 logs/system_report_2026-04-14.log create mode 100644 logs/user_info.log create mode 100644 run_all.sh create mode 100644 scripts/backup.sh create mode 100644 scripts/file_manager.sh create mode 100644 scripts/process_monitor.sh create mode 100644 scripts/system_check.sh create mode 100644 scripts/user_info.sh diff --git a/READ.me b/READ.me new file mode 100644 index 0000000..e69de29 diff --git a/logs/process_monitor.log b/logs/process_monitor.log new file mode 100644 index 0000000..38b930e --- /dev/null +++ b/logs/process_monitor.log @@ -0,0 +1 @@ +Tue Apr 14 12:13:36 WAT 2026: Checked diff --git a/logs/system_report_2026-04-14.log b/logs/system_report_2026-04-14.log new file mode 100644 index 0000000..1b50ae6 --- /dev/null +++ b/logs/system_report_2026-04-14.log @@ -0,0 +1,32 @@ +System Report - Tue Apr 14 11:54:40 WAT 2026 +Disk Usage: +Filesystem Size Used Avail Use% Mounted on +none 3.8G 0 3.8G 0% /usr/lib/modules/6.6.87.2-microsoft-standard-WSL2 +none 3.8G 4.0K 3.8G 1% /mnt/wsl +drivers 476G 446G 31G 94% /usr/lib/wsl/drivers +/dev/sdd 1007G 1.7G 954G 1% / +none 3.8G 92K 3.8G 1% /mnt/wslg +none 3.8G 0 3.8G 0% /usr/lib/wsl/lib +rootfs 3.8G 2.7M 3.8G 1% /init +none 3.8G 500K 3.8G 1% /run +none 3.8G 0 3.8G 0% /run/lock +none 3.8G 0 3.8G 0% /run/shm +none 3.8G 76K 3.8G 1% /mnt/wslg/versions.txt +none 3.8G 76K 3.8G 1% /mnt/wslg/doc +C:\ 476G 446G 31G 94% /mnt/c +tmpfs 761M 8.0K 761M 1% /run/user/1000 +Memory Usage: + total used free shared buff/cache available +Mem: 7608 321 7151 3 134 7137 +Swap: 2048 0 2048 +CPU Load: + 11:54:41 up 3:38, 1 user, load average: 0.00, 0.00, 0.00 +Total Processes: +27 +Top 5 Memory Processes: +USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND +root 258 0.0 0.2 107172 21504 ? Ssl 08:15 0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal +root 202 0.0 0.2 30184 18688 ? Ss 08:15 0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers +root 69 0.0 0.1 47736 15232 ? S> "$LOG_FILE" +done diff --git a/scripts/backup.sh b/scripts/backup.sh new file mode 100644 index 0000000..8ba2b28 --- /dev/null +++ b/scripts/backup.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +LOG_FILE="../logs/backup.log" +BACKUP_DIR="../backups" + +input_dir=$1 + +# Validate directory +if [[ ! -d "$input_dir" ]]; then + echo "Directory does not exist!" + exit 1 +fi + +timestamp=$(date +%Y%m%d_%H%M%S) +backup_file="$BACKUP_DIR/backup_$timestamp.tar.gz" + +# Create backup +tar -czf "$backup_file" "$input_dir" + +echo "Backup created: $backup_file" + +# Keep only last 5 backups +ls -t $BACKUP_DIR | tail -n +6 | while read file; do + rm "$BACKUP_DIR/$file" +done + +# Log +echo "$(date): Backup created for $input_dir" >> "$LOG_FILE" diff --git a/scripts/file_manager.sh b/scripts/file_manager.sh new file mode 100644 index 0000000..0fb6691 --- /dev/null +++ b/scripts/file_manager.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +LOG_FILE="../logs/file_manager.log" + +action=$1 +file1=$2 +file2=$3 + +case $action in + create) + if [[ -f "$file1" ]]; then + echo "File already exists!" + else + touch "$file1" + echo "File created: $file1" + fi + ;; + delete) + if [[ -f "$file1" ]]; then + rm "$file1" + echo "File deleted: $file1" + else + echo "File not found!" + fi + ;; + list) + ls + ;; + rename) + if [[ -f "$file1" ]]; then + mv "$file1" "$file2" + echo "Renamed to $file2" + else + echo "File not found!" + fi + ;; + *) + echo "Invalid command" + ;; +esac + +# Log action +echo "$(date): $action $file1 $file2" >> "$LOG_FILE" diff --git a/scripts/process_monitor.sh b/scripts/process_monitor.sh new file mode 100644 index 0000000..0be96f3 --- /dev/null +++ b/scripts/process_monitor.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +LOG_FILE="../logs/process_monitor.log" + +services=("nginx" "ssh" "docker") + +process=$1 + +if pgrep "$process" > /dev/null +then + echo "$process is Running" +else + echo "$process is Stopped. Restarting..." + echo "Restarted $process (simulated)" +fi + +echo "$(date): Checked $process" >> "$LOG_FILE" diff --git a/scripts/system_check.sh b/scripts/system_check.sh new file mode 100644 index 0000000..db5cde2 --- /dev/null +++ b/scripts/system_check.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +LOG_FILE="../logs/system_report_$(date +%F).log" + +echo "System Report - $(date)" | tee "$LOG_FILE" + +echo "Disk Usage:" | tee -a "$LOG_FILE" +df -h | tee -a "$LOG_FILE" + +usage=$(df / | awk 'NR==2 {print $5}' | sed 's/%//') + +if (( usage > 80 )); then + echo "WARNING: Disk usage above 80%" | tee -a "$LOG_FILE" +fi + +echo "Memory Usage:" | tee -a "$LOG_FILE" +free -m | tee -a "$LOG_FILE" + +echo "CPU Load:" | tee -a "$LOG_FILE" +uptime | tee -a "$LOG_FILE" + +echo "Total Processes:" | tee -a "$LOG_FILE" +ps aux | wc -l | tee -a "$LOG_FILE" + +echo "Top 5 Memory Processes:" | tee -a "$LOG_FILE" +ps aux --sort=-%mem | head -n 6 | tee -a "$LOG_FILE" diff --git a/scripts/user_info.sh b/scripts/user_info.sh new file mode 100644 index 0000000..ef68348 --- /dev/null +++ b/scripts/user_info.sh @@ -0,0 +1,24 @@ +#!/bin/bash +mkdir -p ../logs +LOG_FILE="../logs/user_info.log" +read -p "Enter your name: " name +read -p "Enter your age: " age +read -p "Enter your country: " country +if [[ -z "$name" || -z "$age" || -z "$country" ]]; then +echo "Error: ALL FIELDS ARE REQUIRED!" +exit 1 +fi +if ! [[ "$age" =~ ^[0-9]+$ ]]; then +echo "Error: AGE MUST BE A NUMBER!" +exit 1 +fi +if (( age < 18 )); then +category="minor" +elif (( age <= 65 )); then +category= "Adult" +else +category= "senior" +fi +message="Hello $name from $country. you are $age years old ($category)." +echo "$message" +echo "$(date): $message" >> "$LOG_FILE"