From bb35587f61c8a9275fe871bd7b96d099575af9fc Mon Sep 17 00:00:00 2001 From: Chibuzo Anosike Date: Sun, 5 Apr 2026 13:07:01 +0100 Subject: [PATCH 1/2] feat: complete bash scripts --- run_all.sh | 0 scripts/backup.sh | 0 scripts/file_manager.sh | 0 scripts/process_monitor.sh | 0 scripts/sdystem_check.sh | 0 scripts/user_info.sh | 0 6 files changed, 0 insertions(+), 0 deletions(-) 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/sdystem_check.sh create mode 100644 scripts/user_info.sh diff --git a/run_all.sh b/run_all.sh new file mode 100644 index 0000000..e69de29 diff --git a/scripts/backup.sh b/scripts/backup.sh new file mode 100644 index 0000000..e69de29 diff --git a/scripts/file_manager.sh b/scripts/file_manager.sh new file mode 100644 index 0000000..e69de29 diff --git a/scripts/process_monitor.sh b/scripts/process_monitor.sh new file mode 100644 index 0000000..e69de29 diff --git a/scripts/sdystem_check.sh b/scripts/sdystem_check.sh new file mode 100644 index 0000000..e69de29 diff --git a/scripts/user_info.sh b/scripts/user_info.sh new file mode 100644 index 0000000..e69de29 From 18a601d54da358b417abf9d16f00bb4cfc42a1a2 Mon Sep 17 00:00:00 2001 From: Chibuzo Anosike Date: Sun, 5 Apr 2026 22:03:49 +0100 Subject: [PATCH 2/2] feat: complete bash toolkit --- run_all.sh | 34 +++++++++++++++++++++++++++++ scripts/backup.sh | 23 ++++++++++++++++++++ scripts/file_manager.sh | 44 ++++++++++++++++++++++++++++++++++++++ scripts/process_monitor.sh | 14 ++++++++++++ scripts/system_check.sh | 27 +++++++++++++++++++++++ scripts/user_info.sh | 31 +++++++++++++++++++++++++++ 6 files changed, 173 insertions(+) create mode 100644 scripts/system_check.sh diff --git a/run_all.sh b/run_all.sh index e69de29..3715f44 100644 --- a/run_all.sh +++ b/run_all.sh @@ -0,0 +1,34 @@ +#!/bin/bash +set -euo pipefail + +LOG_FILE="logs/app.log" + +while true; do + echo "1. Run all" + echo "2. System check" + echo "3. Backup" + echo "4. Exit" + + read -p "Choose option: " choice + + case $choice in + 1) + ./scripts/user_info.sh + ./scripts/system_check.sh + echo "Ran all scripts" >> $LOG_FILE + ;; + 2) + ./scripts/system_check.sh + ;; + 3) + read -p "Enter directory to backup: " dir + ./scripts/backup.sh $dir + ;; + 4) + exit 0 + ;; + *) + echo "Invalid choice" + ;; + esac +done diff --git a/scripts/backup.sh b/scripts/backup.sh index e69de29..2655af0 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +LOG_FILE="../logs/backup.log" +BACKUP_DIR="../backups" + +mkdir -p $BACKUP_DIR + +dir=$1 + +if [ ! -d "$dir" ]; then + echo "Directory does not exist!" | tee -a $LOG_FILE + exit 1 +fi + +timestamp=$(date +%Y%m%d_%H%M%S) +backup_file=$BACKUP_DIR/backup_$timestamp.tar.gz" + +tar -czf $backup_file $dir + +echo "Backup created: $backup_file" | tee -a $LOG_FILE + +# Keep only last 5 backups +ls -t $BACKUP_DIR | tail -n +6 | xargs -I {} rm -- "$BACKUP_DIR/{}" diff --git a/scripts/file_manager.sh b/scripts/file_manager.sh index e69de29..ee24303 100644 --- a/scripts/file_manager.sh +++ b/scripts/file_manager.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +LOG_FILE="../logs/file_manager.log" + +action=$1 +file=$2 +new_name=$3 + +case $action in + create) + if [ -f "$file" ]; then + echo "File already exists!" | tee -a $LOG_FILE + else + touch "$file" + echo "Created $file" | tee -a $LOG_FILE + fi + ;; + + delete) + if [ -f "$file" ]; then + rm "$file" + echo "Deleted $file" | tee -a $LOG_FILE + else + echo " File not found!" | tee -a $LOG_FILE + fi + ;; + + list) + ls -l | tee -a $LOG_FILE + ;; + + rename) + if [ -f "$file" ]; then + mv "$file" "$new_name" + echo "Renamed $file to $new_name" | tee -a $LOG_FILE + else + echo "File not found!" | tee -a $LOG_FILE + fi + ;; + + *) + echo "Invalid command" | tee -a $LOG_FILE + ;; +esac diff --git a/scripts/process_monitor.sh b/scripts/process_monitor.sh index e69de29..e8ce5e0 100644 --- a/scripts/process_monitor.sh +++ b/scripts/process_monitor.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +LOG_FILE="../logs/process_monitor.log" +services=("nginx" "ssh" "docker") + +process=$1 + +if pgrep $process > /dev/null +then + echo "$process is Running" | tee -a LOG_FILE +else + echo "$process is stopped. Restarting..." | tee -a $LOG_FILE + echo "$process Restarted (simulated)" | tee -a $LOG_FILE +fi diff --git a/scripts/system_check.sh b/scripts/system_check.sh new file mode 100644 index 0000000..c0eb331 --- /dev/null +++ b/scripts/system_check.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +DATE=$(date +%Y-%M-%d) +LOG_FILE="../logs/system_report_$DATE.log" + +echo "System Report - $DATE" | tee $LOG_FILE + +echo "Disk Usage:" | tee -a $LOG_FILE +df -h | tee -a $LOG_FILE + +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 + +# Disk warning +df -h | awk '$5 > 80 {print "Warning; High disk usage on " $6}' | tee -a $LOG_FILE + +# Process count +echo "Total Processes:" | tee -a $LOG_FILE +ps aux | wc -1 | tee -a $LOG_FILE + +# Top 5 memory processes +echo "Top 5 Memory Consuming 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 index e69de29..7fc7b20 100644 --- a/scripts/user_info.sh +++ b/scripts/user_info.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +LOG_FILE="../logs/user_info.log" + +read -p "Enter your name: " name +read -p "Enter your age: " age +read -p "Enter your country: " country + +# Validate inputs +if [[ -z "$name" || -z "$age || -z "$country" ]]; then + echo "Error: All fields are required." | tee -a $LOG_FILE + exit 1 +f1 + +if ! [[ "$age" =~ ^[0-9]+$ ]]; then + echo "Error: Age must be a number." | tee -a $LOG_FILE + exit 1 +f1 + +# Age category +if [ "$age" -1t 18 ]; then + category="Minor" +elif [ "$age" -1e 65 ]; then + category="Adult" +else + category="Senior" +fi + +message="Hello $name from $country. You are an $category." + +echo $message | tee -a $LOG_FILE