diff --git a/README.md b/README.md index 07a3112..6479c6b 100644 --- a/README.md +++ b/README.md @@ -1,230 +1,230 @@ -# 🚀 DevOps Bash Toolkit Assessment - -![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/your-username/devops-bash-toolkit/grade.yml) -![GitHub repo size](https://img.shields.io/github/repo-size/your-username/devops-bash-toolkit) -![GitHub last commit](https://img.shields.io/github/last-commit/your-username/devops-bash-toolkit) -![License](https://img.shields.io/badge/license-MIT-blue) - ---- - -## 📌 Overview - -This assignment tests your **DevOps fundamentals**: - -- Bash scripting -- Git workflow (branching, commits, pull requests) -- Automation mindset -- System monitoring and logging - -You will build a **real-world automation toolkit** and submit it via a **Pull Request (PR)**. - ---- - -## 📁 Project Structure - -```text -devops-bash-toolkit-assestment/ -│ -├── scripts/ -│ ├── user_info.sh -│ ├── system_check.sh -│ ├── file_manager.sh -│ ├── backup.sh -│ ├── process_monitor.sh -│ -├── run_all.sh # OPTIONAL (Bonus) -│ -├── README.md -``` - -🧑‍💻 Getting Started -1. Fork the Repository - -Click the Fork button on GitHub. - -2. Clone Your Fork -```bash -git clone -cd devops-bash-toolkit -``` - -3. Create a Feature Branch -```bash -git checkout -b feature/ -``` - -4. Complete the Scripts -Implement all required scripts inside: -```bash -scripts/ -``` - -5. Make Scripts Executable -```bash -chmod +x scripts/*.sh -``` - -6. Commit Your Work -```bash -git add . -git commit -m "feat: complete bash scripts" -``` - -7. Push to GitHub -```bash -git push origin feature/ -``` - -8. Create Pull Request - -Open a Pull Request to the main repository. - - -🧠 Assignment Tasks --------------------------------------------------------------------------------- -🔹 A. user_info.sh -Requirements - -* Prompt the user for: - - * Name - - * Age - - * Country - -* Validate: - - * Age must be numeric - -* Output: - - * A greeting message - -* Age category: - - * Minor (<18) - - * Adult (18–65) - - * Senior (65+) - -* Handle missing or invalid input gracefully - -* Save output to: -```bash -logs/user_info.log -``` ---- -🔹 B. system_check.sh -Requirements - -* Display: - - * Disk usage (df -h) - - * Memory usage (free -m) - - * CPU load (uptime) - -* Warn if disk usage exceeds 80% - -* Save report to: -```bash -logs/system_report_.log -``` -* Count total running processes - -* Display top 5 memory-consuming processes ---- -🔹 C. file_manager.sh -Requirements - -* Support the following commands: - - * create - - * delete - - * list - - * rename - -* Example usage: -```bash -./file_manager.sh create file.txt -``` -* Prevent overwriting existing files - -* Log all actions to: -```bash -logs/file_manager.log -``` ---- -🔹 D. backup.sh -Requirements - -* Accept a directory as input - -* Validate that the directory exists - -* Create a compressed backup: -```bash -backup_.tar.gz -``` -* Store backups in: -```bash -backups/ -``` -* Keep only the last 5 backups (delete older ones) - -* Log backup activity ---- -⭐ E. process_monitor.sh(Optional Bonus) -Requirements - -* Accept a process name as input - -* Check if the process is running - -* If NOT running: - - * Attempt restart (or simulate restart) - -* Output: - - * Running - - * Stopped - - * Restarted - -* Use an array: -```bash -services=("nginx" "ssh" "docker") -``` -* Log monitoring results ---- -⭐ F. run_all.sh (Optional Bonus) -Requirements - -Provide an interactive menu: -1. Run all -2. System check -3. Backup -4. Exit -* Use functions to organize logic - -* Call scripts from the scripts/ directory - -* Include: - ```bash - set -euo pipefail - ``` -* Log all actions to: -```bash -logs/app.log -``` -* Handle script failures gracefully - -**Submission link:** [CLICK HERE](https://forms.gle/jrhpKjXsQXZxLopN6) +# 🚀 DevOps Bash Toolkit Assessment + +![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/your-username/devops-bash-toolkit/grade.yml) +![GitHub repo size](https://img.shields.io/github/repo-size/your-username/devops-bash-toolkit) +![GitHub last commit](https://img.shields.io/github/last-commit/your-username/devops-bash-toolkit) +![License](https://img.shields.io/badge/license-MIT-blue) + +--- + +## 📌 Overview + +This assignment tests your **DevOps fundamentals**: + +- Bash scripting +- Git workflow (branching, commits, pull requests) +- Automation mindset +- System monitoring and logging + +You will build a **real-world automation toolkit** and submit it via a **Pull Request (PR)**. + +--- + +## 📁 Project Structure + +```text +devops-bash-toolkit-assestment/ +│ +├── scripts/ +│ ├── user_info.sh +│ ├── system_check.sh +│ ├── file_manager.sh +│ ├── backup.sh +│ ├── process_monitor.sh +│ +├── run_all.sh # OPTIONAL (Bonus) +│ +├── README.md +``` + +🧑‍💻 Getting Started +1. Fork the Repository + +Click the Fork button on GitHub. + +2. Clone Your Fork +```bash +git clone +cd devops-bash-toolkit +``` + +3. Create a Feature Branch +```bash +git checkout -b feature/ +``` + +4. Complete the Scripts +Implement all required scripts inside: +```bash +scripts/ +``` + +5. Make Scripts Executable +```bash +chmod +x scripts/*.sh +``` + +6. Commit Your Work +```bash +git add . +git commit -m "feat: complete bash scripts" +``` + +7. Push to GitHub +```bash +git push origin feature/ +``` + +8. Create Pull Request + +Open a Pull Request to the main repository. + + +🧠 Assignment Tasks +-------------------------------------------------------------------------------- +🔹 A. user_info.sh +Requirements + +* Prompt the user for: + + * Name + + * Age + + * Country + +* Validate: + + * Age must be numeric + +* Output: + + * A greeting message + +* Age category: + + * Minor (<18) + + * Adult (18–65) + + * Senior (65+) + +* Handle missing or invalid input gracefully + +* Save output to: +```bash +logs/user_info.log +``` +--- +🔹 B. system_check.sh +Requirements + +* Display: + + * Disk usage (df -h) + + * Memory usage (free -m) + + * CPU load (uptime) + +* Warn if disk usage exceeds 80% + +* Save report to: +```bash +logs/system_report_.log +``` +* Count total running processes + +* Display top 5 memory-consuming processes +--- +🔹 C. file_manager.sh +Requirements + +* Support the following commands: + + * create + + * delete + + * list + + * rename + +* Example usage: +```bash +./file_manager.sh create file.txt +``` +* Prevent overwriting existing files + +* Log all actions to: +```bash +logs/file_manager.log +``` +--- +🔹 D. backup.sh +Requirements + +* Accept a directory as input + +* Validate that the directory exists + +* Create a compressed backup: +```bash +backup_.tar.gz +``` +* Store backups in: +```bash +backups/ +``` +* Keep only the last 5 backups (delete older ones) + +* Log backup activity +--- +⭐ E. process_monitor.sh(Optional Bonus) +Requirements + +* Accept a process name as input + +* Check if the process is running + +* If NOT running: + + * Attempt restart (or simulate restart) + +* Output: + + * Running + + * Stopped + + * Restarted + +* Use an array: +```bash +services=("nginx" "ssh" "docker") +``` +* Log monitoring results +--- +⭐ F. run_all.sh (Optional Bonus) +Requirements + +Provide an interactive menu: +1. Run all +2. System check +3. Backup +4. Exit +* Use functions to organize logic + +* Call scripts from the scripts/ directory + +* Include: + ```bash + set -euo pipefail + ``` +* Log all actions to: +```bash +logs/app.log +``` +* Handle script failures gracefully + +**Submission link:** [CLICK HERE](https://forms.gle/jrhpKjXsQXZxLopN6) diff --git a/backups/backup_scripts_2026-05-06_09-49-12.tar.gz b/backups/backup_scripts_2026-05-06_09-49-12.tar.gz new file mode 100644 index 0000000..2636202 Binary files /dev/null and b/backups/backup_scripts_2026-05-06_09-49-12.tar.gz differ diff --git a/backups/backup_scripts_2026-05-06_09-59-44.tar.gz b/backups/backup_scripts_2026-05-06_09-59-44.tar.gz new file mode 100644 index 0000000..3d9bc85 Binary files /dev/null and b/backups/backup_scripts_2026-05-06_09-59-44.tar.gz differ diff --git a/backups/backup_scripts_2026-05-06_10-03-22.tar.gz b/backups/backup_scripts_2026-05-06_10-03-22.tar.gz new file mode 100644 index 0000000..3d9bc85 Binary files /dev/null and b/backups/backup_scripts_2026-05-06_10-03-22.tar.gz differ diff --git a/logs/app.log b/logs/app.log new file mode 100644 index 0000000..fa832e5 --- /dev/null +++ b/logs/app.log @@ -0,0 +1,23 @@ +2026-05-06 09:59:15 - Running ALL scripts +2026-05-06 09:59:15 - START: User Info +2026-05-06 09:59:43 - SUCCESS: User Info +2026-05-06 09:59:43 - START: System Check +2026-05-06 09:59:44 - SUCCESS: System Check +2026-05-06 09:59:44 - START: Backup +2026-05-06 09:59:44 - SUCCESS: Backup +2026-05-06 09:59:44 - START: Process Monitor +2026-05-06 09:59:45 - SUCCESS: Process Monitor +2026-05-06 09:59:45 - START: File Manager (list) +2026-05-06 09:59:46 - SUCCESS: File Manager (list) +2026-05-06 10:00:55 - Running ALL scripts +2026-05-06 10:00:55 - START: User Info +2026-05-06 10:03:21 - SUCCESS: User Info +2026-05-06 10:03:21 - START: System Check +2026-05-06 10:03:21 - SUCCESS: System Check +2026-05-06 10:03:21 - START: Backup +2026-05-06 10:03:22 - SUCCESS: Backup +2026-05-06 10:03:22 - START: Process Monitor +2026-05-06 10:03:23 - SUCCESS: Process Monitor +2026-05-06 10:03:23 - START: File Manager (list) +2026-05-06 10:03:23 - SUCCESS: File Manager (list) +2026-05-06 10:03:29 - Exiting application diff --git a/logs/backup.log b/logs/backup.log new file mode 100644 index 0000000..c55421a --- /dev/null +++ b/logs/backup.log @@ -0,0 +1,12 @@ +===== BACKUP STARTED ===== +Backup created: backups/backup_scripts_2026-05-06_09-49-12.tar.gz +Cleaning old backups (keeping last 5)... +===== BACKUP COMPLETED ===== +===== BACKUP STARTED ===== +Backup created: backups/backup_scripts_2026-05-06_09-59-44.tar.gz +Cleaning old backups (keeping last 5)... +===== BACKUP COMPLETED ===== +===== BACKUP STARTED ===== +Backup created: backups/backup_scripts_2026-05-06_10-03-22.tar.gz +Cleaning old backups (keeping last 5)... +===== BACKUP COMPLETED ===== diff --git a/logs/file_manager.log b/logs/file_manager.log new file mode 100644 index 0000000..f4af6ba --- /dev/null +++ b/logs/file_manager.log @@ -0,0 +1,30 @@ +===== FILE MANAGER ACTION: create ===== +File 'file.txt' created. +===== FILE MANAGER ACTION: list ===== +Listing files: +total 4.0K +-rwxrwxrwx 1 root root 3.9K May 6 04:59 README.md +-rwxrwxrwx 1 root root 0 May 6 09:44 file.txt +drwxrwxrwx 1 root root 4.0K May 6 09:44 logs +-rwxrwxrwx 1 root root 0 May 6 07:39 run_all.sh +drwxrwxrwx 1 root root 4.0K May 6 09:44 scripts +===== FILE MANAGER ACTION: rename ===== +Renamed 'file.txt' to 'newfile.txt'. +===== FILE MANAGER ACTION: delete ===== +File 'newfile.txt' deleted. +===== FILE MANAGER ACTION: list ===== +Listing files: +total 8.0K +-rwxrwxrwx 1 root root 3.9K May 6 04:59 README.md +drwxrwxrwx 1 root root 4.0K May 6 09:59 backups +drwxrwxrwx 1 root root 4.0K May 6 09:59 logs +-rwxrwxrwx 1 root root 1.7K May 6 09:57 run_all.sh +drwxrwxrwx 1 root root 4.0K May 6 09:54 scripts +===== FILE MANAGER ACTION: list ===== +Listing files: +total 8.0K +-rwxrwxrwx 1 root root 3.9K May 6 04:59 README.md +drwxrwxrwx 1 root root 4.0K May 6 10:03 backups +drwxrwxrwx 1 root root 4.0K May 6 10:03 logs +-rwxrwxrwx 1 root root 1.7K May 6 09:57 run_all.sh +drwxrwxrwx 1 root root 4.0K May 6 09:54 scripts diff --git a/logs/process_monitor.log b/logs/process_monitor.log new file mode 100644 index 0000000..8ea342e --- /dev/null +++ b/logs/process_monitor.log @@ -0,0 +1,21 @@ +===== PROCESS MONITOR ===== +Date: Wed May 6 09:55:13 WAT 2026 + +Status: Stopped +Attempting to restart nginx... +Status: Restarted +===== CHECK COMPLETED ===== +===== PROCESS MONITOR ===== +Date: Wed May 6 09:59:44 WAT 2026 + +Status: Stopped +Attempting to restart nginx... +Status: Restarted +===== CHECK COMPLETED ===== +===== PROCESS MONITOR ===== +Date: Wed May 6 10:03:22 WAT 2026 + +Status: Stopped +Attempting to restart nginx... +Status: Restarted +===== CHECK COMPLETED ===== diff --git a/logs/system_report_2026-05-06_09-34-45.log b/logs/system_report_2026-05-06_09-34-45.log new file mode 100644 index 0000000..08cd43d --- /dev/null +++ b/logs/system_report_2026-05-06_09-34-45.log @@ -0,0 +1,34 @@ +===== SYSTEM REPORT ===== +Date: Wed May 6 09:34:45 WAT 2026 + +===== DISK USAGE ===== +Filesystem Size Used Avail Use% Mounted on +rootfs 931G 76G 856G 9% / +none 931G 76G 856G 9% /dev +none 931G 76G 856G 9% /run +none 931G 76G 856G 9% /run/lock +none 931G 76G 856G 9% /run/shm +none 931G 76G 856G 9% /run/user +tmpfs 931G 76G 856G 9% /sys/fs/cgroup +C:\ 931G 76G 856G 9% /mnt/c + + +===== MEMORY USAGE ===== + total used free shared buff/cache available +Mem: 16303 5387 10692 17 223 10785 +Swap: 49152 0 49152 + +===== CPU LOAD ===== + 09:34:45 up 1:22, 0 users, load average: 0.52, 0.58, 0.59 + +===== TOTAL RUNNING PROCESSES ===== +8 + +===== TOP 5 MEMORY-CONSUMING PROCESSES ===== +USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND +root 7 0.0 0.0 18084 3608 tty1 S 08:12 0:00 -bash +root 136 4.0 0.0 16796 1968 tty1 S 09:34 0:00 bash scripts/system_check.sh +root 179 0.0 0.0 18660 1876 tty1 R 09:34 0:00 ps aux --sort=-%mem +root 180 0.0 0.0 15288 840 tty1 S 09:34 0:00 head -6 +root 181 0.0 0.0 15284 840 tty1 S 09:34 0:00 tee -a logs/system_report_2026-05-06_09-34-45.log + diff --git a/logs/system_report_2026-05-06_09-42-10.log b/logs/system_report_2026-05-06_09-42-10.log new file mode 100644 index 0000000..f0812b7 --- /dev/null +++ b/logs/system_report_2026-05-06_09-42-10.log @@ -0,0 +1,34 @@ +===== SYSTEM REPORT ===== +Date: Wed May 6 09:42:10 WAT 2026 + +===== DISK USAGE ===== +Filesystem Size Used Avail Use% Mounted on +rootfs 931G 76G 856G 9% / +none 931G 76G 856G 9% /dev +none 931G 76G 856G 9% /run +none 931G 76G 856G 9% /run/lock +none 931G 76G 856G 9% /run/shm +none 931G 76G 856G 9% /run/user +tmpfs 931G 76G 856G 9% /sys/fs/cgroup +C:\ 931G 76G 856G 9% /mnt/c + + +===== MEMORY USAGE ===== + total used free shared buff/cache available +Mem: 16303 5375 10704 17 223 10797 +Swap: 49152 0 49152 + +===== CPU LOAD ===== + 09:42:10 up 1:30, 0 users, load average: 0.52, 0.58, 0.59 + +===== TOTAL RUNNING PROCESSES ===== +8 + +===== TOP 5 MEMORY-CONSUMING PROCESSES ===== +USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND +root 7 0.0 0.0 18084 3612 tty1 S 08:12 0:00 -bash +root 187 8.0 0.0 16796 1968 tty1 S 09:42 0:00 bash scripts/system_check.sh +root 230 0.0 0.0 18660 1876 tty1 R 09:42 0:00 ps aux --sort=-%mem +root 231 0.0 0.0 15288 844 tty1 S 09:42 0:00 head -6 +root 232 0.0 0.0 15284 836 tty1 S 09:42 0:00 tee -a logs/system_report_2026-05-06_09-42-10.log + diff --git a/logs/system_report_2026-05-06_09-59-43.log b/logs/system_report_2026-05-06_09-59-43.log new file mode 100644 index 0000000..93c3b30 --- /dev/null +++ b/logs/system_report_2026-05-06_09-59-43.log @@ -0,0 +1,34 @@ +===== SYSTEM REPORT ===== +Date: Wed May 6 09:59:43 WAT 2026 + +===== DISK USAGE ===== +Filesystem Size Used Avail Use% Mounted on +rootfs 931G 76G 856G 9% / +none 931G 76G 856G 9% /dev +none 931G 76G 856G 9% /run +none 931G 76G 856G 9% /run/lock +none 931G 76G 856G 9% /run/shm +none 931G 76G 856G 9% /run/user +tmpfs 931G 76G 856G 9% /sys/fs/cgroup +C:\ 931G 76G 856G 9% /mnt/c + + +===== MEMORY USAGE ===== + total used free shared buff/cache available +Mem: 16303 5489 10589 17 223 10682 +Swap: 49152 0 49152 + +===== CPU LOAD ===== + 09:59:43 up 1:47, 0 users, load average: 0.52, 0.58, 0.59 + +===== TOTAL RUNNING PROCESSES ===== +9 + +===== TOP 5 MEMORY-CONSUMING PROCESSES ===== +USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND +root 7 0.0 0.0 18084 3612 tty1 S 08:12 0:00 -bash +root 315 0.0 0.0 16796 2056 tty1 S 09:58 0:00 bash run_all.sh +root 338 0.0 0.0 16796 1968 tty1 S 09:59 0:00 bash scripts/system_check.sh +root 381 0.0 0.0 18660 1876 tty1 R 09:59 0:00 ps aux --sort=-%mem +root 382 0.0 0.0 15288 844 tty1 S 09:59 0:00 head -6 + diff --git a/logs/system_report_2026-05-06_10-03-21.log b/logs/system_report_2026-05-06_10-03-21.log new file mode 100644 index 0000000..2194b6f --- /dev/null +++ b/logs/system_report_2026-05-06_10-03-21.log @@ -0,0 +1,34 @@ +===== SYSTEM REPORT ===== +Date: Wed May 6 10:03:21 WAT 2026 + +===== DISK USAGE ===== +Filesystem Size Used Avail Use% Mounted on +rootfs 931G 76G 856G 9% / +none 931G 76G 856G 9% /dev +none 931G 76G 856G 9% /run +none 931G 76G 856G 9% /run/lock +none 931G 76G 856G 9% /run/shm +none 931G 76G 856G 9% /run/user +tmpfs 931G 76G 856G 9% /sys/fs/cgroup +C:\ 931G 76G 856G 9% /mnt/c + + +===== MEMORY USAGE ===== + total used free shared buff/cache available +Mem: 16303 5495 10583 17 223 10676 +Swap: 49152 0 49152 + +===== CPU LOAD ===== + 10:03:21 up 1:51, 0 users, load average: 0.52, 0.58, 0.59 + +===== TOTAL RUNNING PROCESSES ===== +9 + +===== TOP 5 MEMORY-CONSUMING PROCESSES ===== +USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND +root 7 0.0 0.0 18084 3612 tty1 S 08:12 0:00 -bash +root 315 0.0 0.0 16796 2060 tty1 S 09:58 0:00 bash run_all.sh +root 474 10.0 0.0 16796 1972 tty1 S 10:03 0:00 bash scripts/system_check.sh +root 517 0.0 0.0 18660 1876 tty1 R 10:03 0:00 ps aux --sort=-%mem +root 518 0.0 0.0 15288 844 tty1 S 10:03 0:00 head -6 + diff --git a/logs/user_info.log b/logs/user_info.log new file mode 100644 index 0000000..4824492 --- /dev/null +++ b/logs/user_info.log @@ -0,0 +1,12 @@ +-------------------------------- +Hello Tariq Olugbode from NIGERIA! +You are classified as: Adult +-------------------------------- +-------------------------------- +Hello Tariq Olugbode from NIGERIA! +You are classified as: Adult +-------------------------------- +-------------------------------- +Hello Tariq Olugbode from NIGERIA! +You are classified as: Adult +-------------------------------- diff --git a/run_all.sh b/run_all.sh new file mode 100644 index 0000000..13a0d7a --- /dev/null +++ b/run_all.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +set -euo pipefail + +mkdir -p logs +LOG_FILE="logs/app.log" + +log() { + echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE" +} + +# ------------------------- +# FUNCTIONS +# ------------------------- + +run_all() { + log "Running ALL scripts" + + run_script "User Info" "bash scripts/user_info.sh" + run_script "System Check" "bash scripts/system_check.sh" + run_script "Backup" "bash scripts/backup.sh scripts" + run_script "Process Monitor" "bash scripts/process_monitor.sh nginx" + run_script "File Manager (list)" "bash scripts/file_manager.sh list" +} + +run_system_check() { + log "Running System Check" + run_script "System Check" "bash scripts/system_check.sh" +} + +run_backup() { + read -p "Enter directory to back up: " DIR + log "Running Backup on $DIR" + run_script "Backup" "bash scripts/backup.sh $DIR" +} + +# ------------------------- +# SAFE EXECUTION HANDLER +# ------------------------- +run_script() { + NAME=$1 + CMD=$2 + + echo "" + echo ">>> $NAME" + log "START: $NAME" + + if eval "$CMD"; then + log "SUCCESS: $NAME" + else + log "FAILED: $NAME" + echo "Error occurred in $NAME (continuing...)" + fi +} + +# ------------------------- +# MENU +# ------------------------- +while true; do + echo "" + echo "==============================" + echo " DEVOPS TOOLKIT MENU" + echo "==============================" + echo "1. Run All" + echo "2. System Check" + echo "3. Backup" + echo "4. Exit" + echo "==============================" + + read -p "Choose an option: " CHOICE + + case $CHOICE in + 1) run_all ;; + 2) run_system_check ;; + 3) run_backup ;; + 4) + log "Exiting application" + echo "Goodbye!" + exit 0 + ;; + *) + echo "Invalid option. Try again." + ;; + esac +done diff --git a/scripts/backup.sh b/scripts/backup.sh new file mode 100644 index 0000000..83a2bc5 --- /dev/null +++ b/scripts/backup.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +mkdir -p backups +mkdir -p logs + +LOG_FILE="logs/backup.log" + +SOURCE=$1 +DATE=$(date +"%Y-%m-%d_%H-%M-%S") + +echo "===== BACKUP STARTED =====" | tee -a "$LOG_FILE" + +# ------------------------- +# Validate input +# ------------------------- +if [ -z "$SOURCE" ]; then + echo "Error: No directory provided." | tee -a "$LOG_FILE" + echo "Usage: $0 " | tee -a "$LOG_FILE" + exit 1 +fi + +# ------------------------- +# Check directory exists +# ------------------------- +if [ ! -d "$SOURCE" ]; then + echo "Error: Directory '$SOURCE' does not exist." | tee -a "$LOG_FILE" + exit 1 +fi + +# ------------------------- +# Create backup +# ------------------------- +BACKUP_NAME="backups/backup_$(basename "$SOURCE")_$DATE.tar.gz" + +tar -czf "$BACKUP_NAME" "$SOURCE" + +echo "Backup created: $BACKUP_NAME" | tee -a "$LOG_FILE" + +# ------------------------- +# Keep only last 5 backups +# ------------------------- +echo "Cleaning old backups (keeping last 5)..." | tee -a "$LOG_FILE" + +ls -t backups/*.tar.gz 2>/dev/null | tail -n +6 | while read OLD; do + rm -f "$OLD" + echo "Deleted old backup: $OLD" | tee -a "$LOG_FILE" +done + +echo "===== BACKUP COMPLETED =====" | tee -a "$LOG_FILE" diff --git a/scripts/file_manager.sh b/scripts/file_manager.sh new file mode 100644 index 0000000..7567a82 --- /dev/null +++ b/scripts/file_manager.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +mkdir -p logs +LOG_FILE="logs/file_manager.log" + +ACTION=$1 +FILE=$2 +TARGET=$3 + +echo "===== FILE MANAGER ACTION: $ACTION =====" | tee -a "$LOG_FILE" + +case $ACTION in + +create) + if [ -f "$FILE" ]; then + echo "Error: File '$FILE' already exists." | tee -a "$LOG_FILE" + else + touch "$FILE" + echo "File '$FILE' created." | tee -a "$LOG_FILE" + fi + ;; + +delete) + if [ -f "$FILE" ]; then + rm "$FILE" + echo "File '$FILE' deleted." | tee -a "$LOG_FILE" + else + echo "Error: File not found." | tee -a "$LOG_FILE" + fi + ;; + +list) + echo "Listing files:" | tee -a "$LOG_FILE" + ls -lh | tee -a "$LOG_FILE" + ;; + +rename) + if [ -f "$FILE" ]; then + mv "$FILE" "$TARGET" + echo "Renamed '$FILE' to '$TARGET'." | tee -a "$LOG_FILE" + else + echo "Error: Source file not found." | tee -a "$LOG_FILE" + fi + ;; + +*) + echo "Usage: $0 {create|delete|list|rename}" | tee -a "$LOG_FILE" + echo "Examples:" | tee -a "$LOG_FILE" + echo " $0 create file.txt" | tee -a "$LOG_FILE" + echo " $0 delete file.txt" | tee -a "$LOG_FILE" + echo " $0 list" | tee -a "$LOG_FILE" + echo " $0 rename old.txt new.txt" | tee -a "$LOG_FILE" + ;; + +esac diff --git a/scripts/process_monitor.sh b/scripts/process_monitor.sh new file mode 100644 index 0000000..b73e501 --- /dev/null +++ b/scripts/process_monitor.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +mkdir -p logs +LOG_FILE="logs/process_monitor.log" + +# Predefined services +services=("nginx" "ssh" "docker") + +PROCESS_NAME=$1 + +echo "===== PROCESS MONITOR =====" | tee -a "$LOG_FILE" +echo "Date: $(date)" | tee -a "$LOG_FILE" +echo "" | tee -a "$LOG_FILE" + +# ------------------------- +# Validate input +# ------------------------- +if [ -z "$PROCESS_NAME" ]; then + echo "Error: No process name provided." | tee -a "$LOG_FILE" + echo "Usage: $0 " | tee -a "$LOG_FILE" + exit 1 +fi + +# ------------------------- +# Check if process is in allowed services +# ------------------------- +FOUND=false +for svc in "${services[@]}"; do + if [ "$svc" == "$PROCESS_NAME" ]; then + FOUND=true + break + fi +done + +if [ "$FOUND" = false ]; then + echo "Warning: '$PROCESS_NAME' is not in monitored services list." | tee -a "$LOG_FILE" +fi + +# ------------------------- +# Check if process is running +# ------------------------- +if pgrep -x "$PROCESS_NAME" > /dev/null; then + echo "Status: Running" | tee -a "$LOG_FILE" +else + echo "Status: Stopped" | tee -a "$LOG_FILE" + + # Simulate restart + echo "Attempting to restart $PROCESS_NAME..." | tee -a "$LOG_FILE" + sleep 1 + echo "Status: Restarted" | tee -a "$LOG_FILE" +fi + +echo "" +echo "===== CHECK COMPLETED =====" | tee -a "$LOG_FILE" diff --git a/scripts/system_check.sh b/scripts/system_check.sh new file mode 100644 index 0000000..d183a8b --- /dev/null +++ b/scripts/system_check.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# Create logs folder if it doesn't exist +mkdir -p logs + +# Timestamp for log file +DATE=$(date +"%Y-%m-%d_%H-%M-%S") +LOG_FILE="logs/system_report_$DATE.log" + +echo "===== SYSTEM REPORT =====" | tee -a "$LOG_FILE" +echo "Date: $(date)" | tee -a "$LOG_FILE" +echo "" | tee -a "$LOG_FILE" + +# ======================= +# DISK USAGE +# ======================= +echo "===== DISK USAGE =====" | tee -a "$LOG_FILE" +df -h | tee -a "$LOG_FILE" + +echo "" | tee -a "$LOG_FILE" + +# Check disk usage warning (>80%) +DISK_USAGE=$(df / | awk 'NR==2 {print $5}' | sed 's/%//') + +if [ "$DISK_USAGE" -gt 80 ]; then + echo "WARNING: Disk usage is above 80% ($DISK_USAGE%)" | tee -a "$LOG_FILE" +fi + +echo "" | tee -a "$LOG_FILE" + +# ======================= +# MEMORY USAGE +# ======================= +echo "===== MEMORY USAGE =====" | tee -a "$LOG_FILE" +free -m | tee -a "$LOG_FILE" + +echo "" | tee -a "$LOG_FILE" + +# ======================= +# CPU LOAD +# ======================= +echo "===== CPU LOAD =====" | tee -a "$LOG_FILE" +uptime | tee -a "$LOG_FILE" + +echo "" | tee -a "$LOG_FILE" + +# ======================= +# PROCESS COUNT +# ======================= +echo "===== TOTAL RUNNING PROCESSES =====" | tee -a "$LOG_FILE" +ps aux | wc -l | tee -a "$LOG_FILE" + +echo "" | tee -a "$LOG_FILE" + +# ======================= +# TOP 5 MEMORY PROCESSES +# ======================= +echo "===== TOP 5 MEMORY-CONSUMING PROCESSES =====" | tee -a "$LOG_FILE" +ps aux --sort=-%mem | head -6 | tee -a "$LOG_FILE" + +echo "" | tee -a "$LOG_FILE" + +echo "Report saved to: $LOG_FILE" diff --git a/scripts/user_info.sh b/scripts/user_info.sh new file mode 100644 index 0000000..2949f71 --- /dev/null +++ b/scripts/user_info.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +LOG_FILE="logs/user_info.log" + +echo "===== USER INFORMATION TOOL =====" + +read -p "Enter your name: " NAME +read -p "Enter your age: " AGE +read -p "Enter your country: " COUNTRY + +echo "" + +# Validate input +if [ -z "$NAME" ] || [ -z "$AGE" ] || [ -z "$COUNTRY" ]; then + echo "Error: All fields are required." + exit 1 +fi + +# Check numeric age +if ! [[ "$AGE" =~ ^[0-9]+$ ]]; then + echo "Error: Age must be a number." + exit 1 +fi + +# Age category +if [ "$AGE" -lt 18 ]; then + CATEGORY="Minor" +elif [ "$AGE" -le 65 ]; then + CATEGORY="Adult" +else + CATEGORY="Senior" +fi + +echo "--------------------------------" | tee -a "$LOG_FILE" +echo "Hello $NAME from $COUNTRY!" | tee -a "$LOG_FILE" +echo "You are classified as: $CATEGORY" | tee -a "$LOG_FILE" +echo "--------------------------------" | tee -a "$LOG_FILE"