diff --git a/backups/backup_2026-04-02_03-07-26.tar.gz b/backups/backup_2026-04-02_03-07-26.tar.gz new file mode 100644 index 0000000..cd49905 Binary files /dev/null and b/backups/backup_2026-04-02_03-07-26.tar.gz differ diff --git a/backups/backup_2026-04-02_03-25-34.tar.gz b/backups/backup_2026-04-02_03-25-34.tar.gz new file mode 100644 index 0000000..304c507 Binary files /dev/null and b/backups/backup_2026-04-02_03-25-34.tar.gz differ diff --git a/backups/backup_2026-04-02_03-28-05.tar.gz b/backups/backup_2026-04-02_03-28-05.tar.gz new file mode 100644 index 0000000..2bcfd27 Binary files /dev/null and b/backups/backup_2026-04-02_03-28-05.tar.gz differ diff --git a/logs/app.log b/logs/app.log new file mode 100644 index 0000000..3ce77fe --- /dev/null +++ b/logs/app.log @@ -0,0 +1,4 @@ +2026-04-02 03:22:45 - Running all scripts +2026-04-02 03:26:17 - system check completed +2026-04-02 03:28:05 - backup completed +2026-04-02 03:28:43 - Exiting diff --git a/logs/backup.log b/logs/backup.log new file mode 100644 index 0000000..7c935dc --- /dev/null +++ b/logs/backup.log @@ -0,0 +1,3 @@ +Backup created: backups/backup_2026-04-02_03-07-26.tar.gz +Backup created: backups/backup_2026-04-02_03-25-34.tar.gz +Backup created: backups/backup_2026-04-02_03-28-05.tar.gz diff --git a/logs/file_manager.log b/logs/file_manager.log new file mode 100644 index 0000000..825a5bf --- /dev/null +++ b/logs/file_manager.log @@ -0,0 +1,4 @@ +2026-04-02 02:55:40 - CREATED - test.txt +2026-04-02 02:56:12 - LISTED files +2026-04-02 02:58:31 - RENAMED - test.txt to new.txt +2026-04-02 03:01:20 - DELETED - new.txt diff --git a/logs/process_monitor.log b/logs/process_monitor.log new file mode 100644 index 0000000..94ffa37 --- /dev/null +++ b/logs/process_monitor.log @@ -0,0 +1,2 @@ +2026-04-02 03:16:38 - nginx is Stopped. Restarting... +2026-04-02 03:16:38 - nginx Restarted diff --git a/logs/system_report_2026-04-02_03-10-17.log b/logs/system_report_2026-04-02_03-10-17.log new file mode 100644 index 0000000..5a6bb19 --- /dev/null +++ b/logs/system_report_2026-04-02_03-10-17.log @@ -0,0 +1,41 @@ +===== SYSTEM CHECK REPORT ===== +Date: Thu Apr 2 03:10:17 CDT 2026 + +---- Disk Usage ---- +Filesystem Size Used Avail Use% Mounted on +none 1.9G 0 1.9G 0% /usr/lib/modules/6.6.87.2-microsoft-standard-WSL2 +none 1.9G 4.0K 1.9G 1% /mnt/wsl +drivers 238G 87G 151G 37% /usr/lib/wsl/drivers +/dev/sdd 1007G 1.3G 955G 1% / +none 1.9G 84K 1.9G 1% /mnt/wslg +none 1.9G 0 1.9G 0% /usr/lib/wsl/lib +rootfs 1.9G 2.7M 1.9G 1% /init +none 1.9G 504K 1.9G 1% /run +none 1.9G 0 1.9G 0% /run/lock +none 1.9G 0 1.9G 0% /run/shm +none 1.9G 76K 1.9G 1% /mnt/wslg/versions.txt +none 1.9G 76K 1.9G 1% /mnt/wslg/doc +C:\ 238G 87G 151G 37% /mnt/c +tmpfs 382M 20K 382M 1% /run/user/1000 + +---- Memory Usage ---- + total used free shared buff/cache available +Mem: 3818 477 3311 3 166 3340 +Swap: 1024 0 1024 + +---- CPU Load ---- + 03:10:18 up 54 min, 1 user, load average: 0.04, 0.08, 0.03 + +---- Disk Warning (>80%) ---- + +---- Total Processes ---- +26 + +---- Top 5 Memory Processes ---- + PID COMMAND %MEM + 58 systemd-journal 0.6 + 200 unattended-upgr 0.5 + 1 systemd 0.3 + 117 systemd-resolve 0.3 + 376 systemd 0.2 + diff --git a/logs/system_report_2026-04-02_03-25-09.log b/logs/system_report_2026-04-02_03-25-09.log new file mode 100644 index 0000000..0a908e1 --- /dev/null +++ b/logs/system_report_2026-04-02_03-25-09.log @@ -0,0 +1,41 @@ +===== SYSTEM CHECK REPORT ===== +Date: Thu Apr 2 03:25:09 CDT 2026 + +---- Disk Usage ---- +Filesystem Size Used Avail Use% Mounted on +none 1.9G 0 1.9G 0% /usr/lib/modules/6.6.87.2-microsoft-standard-WSL2 +none 1.9G 4.0K 1.9G 1% /mnt/wsl +drivers 238G 87G 151G 37% /usr/lib/wsl/drivers +/dev/sdd 1007G 1.3G 955G 1% / +none 1.9G 88K 1.9G 1% /mnt/wslg +none 1.9G 0 1.9G 0% /usr/lib/wsl/lib +rootfs 1.9G 2.7M 1.9G 1% /init +none 1.9G 504K 1.9G 1% /run +none 1.9G 0 1.9G 0% /run/lock +none 1.9G 0 1.9G 0% /run/shm +none 1.9G 76K 1.9G 1% /mnt/wslg/versions.txt +none 1.9G 76K 1.9G 1% /mnt/wslg/doc +C:\ 238G 87G 151G 37% /mnt/c +tmpfs 382M 20K 382M 1% /run/user/1000 + +---- Memory Usage ---- + total used free shared buff/cache available +Mem: 3818 485 3298 3 171 3332 +Swap: 1024 0 1024 + +---- CPU Load ---- + 03:25:09 up 1:08, 1 user, load average: 0.06, 0.07, 0.05 + +---- Disk Warning (>80%) ---- + +---- Total Processes ---- +27 + +---- Top 5 Memory Processes ---- + PID COMMAND %MEM + 58 systemd-journal 0.7 + 200 unattended-upgr 0.5 + 1 systemd 0.3 + 117 systemd-resolve 0.3 + 376 systemd 0.2 + diff --git a/logs/system_report_2026-04-02_03-26-17.log b/logs/system_report_2026-04-02_03-26-17.log new file mode 100644 index 0000000..0e9b47a --- /dev/null +++ b/logs/system_report_2026-04-02_03-26-17.log @@ -0,0 +1,41 @@ +===== SYSTEM CHECK REPORT ===== +Date: Thu Apr 2 03:26:17 CDT 2026 + +---- Disk Usage ---- +Filesystem Size Used Avail Use% Mounted on +none 1.9G 0 1.9G 0% /usr/lib/modules/6.6.87.2-microsoft-standard-WSL2 +none 1.9G 4.0K 1.9G 1% /mnt/wsl +drivers 238G 87G 151G 37% /usr/lib/wsl/drivers +/dev/sdd 1007G 1.3G 955G 1% / +none 1.9G 88K 1.9G 1% /mnt/wslg +none 1.9G 0 1.9G 0% /usr/lib/wsl/lib +rootfs 1.9G 2.7M 1.9G 1% /init +none 1.9G 504K 1.9G 1% /run +none 1.9G 0 1.9G 0% /run/lock +none 1.9G 0 1.9G 0% /run/shm +none 1.9G 76K 1.9G 1% /mnt/wslg/versions.txt +none 1.9G 76K 1.9G 1% /mnt/wslg/doc +C:\ 238G 87G 151G 37% /mnt/c +tmpfs 382M 20K 382M 1% /run/user/1000 + +---- Memory Usage ---- + total used free shared buff/cache available +Mem: 3818 482 3301 3 171 3336 +Swap: 1024 0 1024 + +---- CPU Load ---- + 03:26:17 up 1:10, 1 user, load average: 0.02, 0.05, 0.05 + +---- Disk Warning (>80%) ---- + +---- Total Processes ---- +27 + +---- Top 5 Memory Processes ---- + PID COMMAND %MEM + 58 systemd-journal 0.7 + 200 unattended-upgr 0.5 + 1 systemd 0.3 + 117 systemd-resolve 0.3 + 376 systemd 0.2 + diff --git a/logs/user_info.log b/logs/user_info.log new file mode 100644 index 0000000..19a5e0b --- /dev/null +++ b/logs/user_info.log @@ -0,0 +1,2 @@ +2026-04-02 02:49:25 - Hello Sunday from Nigeria. You are 32 years old (Adult). +2026-04-02 03:25:09 - Hello Sunday from Nigeria. You are 32 years old (Adult). diff --git a/run_all.sh b/run_all.sh new file mode 100755 index 0000000..4adc584 --- /dev/null +++ b/run_all.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +set -euo pipefail + +mkdir -p logs +LOG_FILE="logs/app.log" + +log() { + echo "$(date '+%F %T') - $1" | tee -a "$LOG_FILE" +} + +run_all() { + log "Running all scripts" + + ./scripts/user_info.sh || log "user_info failed" + ./scripts/system_check.sh || log "system_check failed" + + read -rp "Enter directory to backup: " dir + ./scripts/backup.sh "$dir" || log "backup failed" +} + +run_system_check() { + ./scripts/system_check.sh && log "system check completed" +} + +run_backup() { + read -rp "Enter directory to backup: " dir + ./scripts/backup.sh "$dir" && log "backup completed" +} + +while true; do + echo + echo "===== MENU =====" + echo "1. Run All" + echo "2. System Check" + echo "3. Backup" + echo "4. Exit" + echo + + read -rp "Choose an option: " choice + + case "$choice" in + 1) run_all ;; + 2) run_system_check ;; + 3) run_backup ;; + 4) log "Exiting"; exit 0 ;; + *) echo "Invalid option" ;; + esac +done diff --git a/scripts/backup.sh b/scripts/backup.sh new file mode 100755 index 0000000..1c7bdaa --- /dev/null +++ b/scripts/backup.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -euo pipefail + +mkdir -p logs backups +LOG_FILE="logs/backup.log" + +target_dir="${1:-}" + +# Validate input +if [[ -z "$target_dir" ]]; then + echo "Usage: $0 " + exit 1 +fi + +if [[ ! -d "$target_dir" ]]; then + echo "Error: Directory does not exist." | tee -a "$LOG_FILE" + exit 1 +fi + +# Create backup +timestamp=$(date '+%F_%H-%M-%S') +backup_file="backups/backup_${timestamp}.tar.gz" + +tar -czf "$backup_file" "$target_dir" + +echo "Backup created: $backup_file" | tee -a "$LOG_FILE" + +# Keep only last 5 backups +ls -1t backups/backup_*.tar.gz 2>/dev/null | tail -n +6 | while read -r old; do + rm -f "$old" + echo "Deleted old backup: $old" >> "$LOG_FILE" +done diff --git a/scripts/file_manager.sh b/scripts/file_manager.sh new file mode 100755 index 0000000..5dd1939 --- /dev/null +++ b/scripts/file_manager.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash +set -euo pipefail + +mkdir -p logs +LOG_FILE="logs/file_manager.log" + +action="${1:-}" + +log() { + echo "$(date '+%F %T') - $1" >> "$LOG_FILE" +} + +case "$action" in + create) + filename="${2:-}" + + if [[ -z "$filename" ]]; then + echo "Usage: $0 create " + exit 1 + fi + + if [[ -e "$filename" ]]; then + echo "Error: File already exists." + log "CREATE FAILED - $filename exists" + exit 1 + fi + + touch "$filename" + echo "Created $filename" + log "CREATED - $filename" + ;; + + delete) + filename="${2:-}" + + if [[ -z "$filename" ]]; then + echo "Usage: $0 delete " + exit 1 + fi + + if [[ ! -e "$filename" ]]; then + echo "Error: File does not exist." + log "DELETE FAILED - $filename not found" + exit 1 + fi + + rm -f "$filename" + echo "Deleted $filename" + log "DELETED - $filename" + ;; + + list) + ls -lah + log "LISTED files" + ;; + + rename) + oldname="${2:-}" + newname="${3:-}" + + if [[ -z "$oldname" || -z "$newname" ]]; then + echo "Usage: $0 rename " + exit 1 + fi + + if [[ ! -e "$oldname" ]]; then + echo "Error: File not found." + log "RENAME FAILED - $oldname not found" + exit 1 + fi + + if [[ -e "$newname" ]]; then + echo "Error: Target file already exists." + log "RENAME FAILED - $newname exists" + exit 1 + fi + + mv "$oldname" "$newname" + echo "Renamed $oldname to $newname" + log "RENAMED - $oldname to $newname" + ;; + + *) + echo "Usage: $0 {create|delete|list|rename}" + exit 1 + ;; +esac diff --git a/scripts/process_monitor.sh b/scripts/process_monitor.sh new file mode 100755 index 0000000..63d4a51 --- /dev/null +++ b/scripts/process_monitor.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -euo pipefail + +mkdir -p logs +LOG_FILE="logs/process_monitor.log" + +services=("nginx" "ssh" "docker") + +process_name="${1:-}" + +if [[ -z "$process_name" ]]; then + echo "Usage: $0 " + exit 1 +fi + +# Check if process is in allowed list +found=false +for service in "${services[@]}"; do + if [[ "$service" == "$process_name" ]]; then + found=true + break + fi +done + +if [[ "$found" == false ]]; then + msg="Process '$process_name' is not monitored." + echo "$msg" + echo "$(date '+%F %T') - $msg" >> "$LOG_FILE" + exit 1 +fi + +# Check if running +if pgrep -x "$process_name" > /dev/null 2>&1; then + msg="$process_name is Running" +else + msg="$process_name is Stopped. Restarting..." + echo "$msg" + + # Simulate restart (safe for assignment) + sleep 1 + + msg2="$process_name Restarted" + echo "$msg2" + + echo "$(date '+%F %T') - $msg" >> "$LOG_FILE" + echo "$(date '+%F %T') - $msg2" >> "$LOG_FILE" + exit 0 +fi + +echo "$msg" +echo "$(date '+%F %T') - $msg" >> "$LOG_FILE" diff --git a/scripts/system_check.sh b/scripts/system_check.sh new file mode 100755 index 0000000..43a6419 --- /dev/null +++ b/scripts/system_check.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -euo pipefail + +mkdir -p logs +REPORT="logs/system_report_$(date '+%F_%H-%M-%S').log" + +{ + echo "===== SYSTEM CHECK REPORT =====" + echo "Date: $(date)" + echo + + echo "---- Disk Usage ----" + df -h + echo + + echo "---- Memory Usage ----" + free -m + echo + + echo "---- CPU Load ----" + uptime + echo + + echo "---- Disk Warning (>80%) ----" + df -h | awk 'NR>1 {gsub("%","",$5); if ($5 > 80) print "WARNING: " $6 " is at " $5 "%"}' + echo + + echo "---- Total Processes ----" + ps -e --no-headers | wc -l + echo + + echo "---- Top 5 Memory Processes ----" + ps -eo pid,comm,%mem --sort=-%mem | head -n 6 + echo + +} | tee "$REPORT" diff --git a/scripts/user_info.sh b/scripts/user_info.sh new file mode 100755 index 0000000..c62ef07 --- /dev/null +++ b/scripts/user_info.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -euo pipefail + +mkdir -p logs +LOG_FILE="logs/user_info.log" + +# Get user input +read -rp "Enter your name: " name +read -rp "Enter your age: " age +read -rp "Enter your country: " country + +# Validate input +if [[ -z "$name" || -z "$age" || -z "$country" ]]; then + echo "Error: All fields are required." | tee -a "$LOG_FILE" + exit 1 +fi + +# Check if age is numeric +if ! [[ "$age" =~ ^[0-9]+$ ]]; then + echo "Error: Age must be a number." | tee -a "$LOG_FILE" + exit 1 +fi + +# Determine age category +if (( age < 18 )); then + category="Minor" +elif (( age < 65 )); then + category="Adult" +else + category="Senior" +fi + +# Output result +message="Hello $name from $country. You are $age years old ($category)." +echo "$message" +echo "$(date '+%F %T') - $message" >> "$LOG_FILE"