diff --git a/backups/backup_20260331_191330.tar.gz b/backups/backup_20260331_191330.tar.gz new file mode 100644 index 0000000..872c015 Binary files /dev/null and b/backups/backup_20260331_191330.tar.gz differ diff --git a/backups/backup_20260331_194052.tar.gz b/backups/backup_20260331_194052.tar.gz new file mode 100644 index 0000000..872c015 Binary files /dev/null and b/backups/backup_20260331_194052.tar.gz differ diff --git a/backups/backup_20260331_201324.tar.gz b/backups/backup_20260331_201324.tar.gz new file mode 100644 index 0000000..376c010 Binary files /dev/null and b/backups/backup_20260331_201324.tar.gz differ diff --git a/backups/backup_20260331_212620.tar.gz b/backups/backup_20260331_212620.tar.gz new file mode 100644 index 0000000..6d764e7 Binary files /dev/null and b/backups/backup_20260331_212620.tar.gz differ diff --git a/backups/backup_20260331_213028.tar.gz b/backups/backup_20260331_213028.tar.gz new file mode 100644 index 0000000..edccd54 Binary files /dev/null and b/backups/backup_20260331_213028.tar.gz differ diff --git a/file_manager.sh b/file_manager.sh new file mode 100644 index 0000000..e9e9032 --- /dev/null +++ b/file_manager.sh @@ -0,0 +1,2 @@ +# jonas dairy + diff --git a/log/app.log b/log/app.log new file mode 100644 index 0000000..3f036d1 --- /dev/null +++ b/log/app.log @@ -0,0 +1,62 @@ +total 24K +-rw-rw-r-- 1 joseph joseph 603 Mar 31 20:06 backup.sh +-rw-rw-r-- 1 joseph joseph 863 Mar 31 18:00 file_manager.sh +-rw-rw-r-- 1 joseph joseph 385 Mar 31 20:58 process_monitor.sh +-rw-rw-r-- 1 joseph joseph 626 Mar 31 21:23 run_all.sh +-rw-rw-r-- 1 joseph joseph 841 Mar 31 15:16 system_check.sh +-rw-rw-r-- 1 joseph joseph 646 Mar 31 14:12 user_info.sh +===== SYSTEM REPORT ===== +--------- Disk Usage --------- +Filesystem Size Used Avail Use% Mounted on +tmpfs 818M 1.6M 816M 1% /run +/dev/sda2 98G 9.8G 84G 11% / +tmpfs 4.0G 0 4.0G 0% /dev/shm +tmpfs 5.0M 8.0K 5.0M 1% /run/lock +tmpfs 818M 148K 818M 1% /run/user/1000 +--------- Memory Usage --------- + total used free shared buff/cache available +Mem: 8172 1526 4552 37 2397 6645 +Swap: 4095 0 4095 +--------- CPU Load --------- + 21:26:20 up 1 day, 24 min, 1 user, load average: 0.01, 0.10, 0.11 +---- total running processes: 204 +----- Top 5 memeory-consuming processes ----- +USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND +joseph 1784 2.8 5.8 4098540 492048 ? Ssl Mar30 41:16 /usr/bin/gnome-shell +joseph 17392 0.1 3.1 1665480 263744 ? Sl 20:32 0:03 /usr/bin/nautilus --gapplication-service +joseph 2248 0.0 2.7 1358796 228068 ? Sl Mar30 0:40 /snap/snapd-desktop-integration/253/usr/bin/snapd-desktop-integration +joseph 1915 0.0 1.3 1138528 109936 ? Sl Mar30 0:01 /usr/libexec/evolution-data-server/evolution-alarm-notify +joseph 14478 0.0 1.1 1109756 98600 ? Sl 12:11 0:00 /usr/libexec/mutter-x11-frames +Backup created: ../backups/backup_20260331_212620.tar.gz +Old backups cleaned up +nginx is stopped. Restarting... +nginx Restarted +ssh is stopped. Restarting... +ssh Restarted +docker is stopped. Restarting... +docker Restarted +Hello Joseph from 9ja! You are an Adult. +===== SYSTEM REPORT ===== +--------- Disk Usage --------- +Filesystem Size Used Avail Use% Mounted on +tmpfs 818M 1.6M 816M 1% /run +/dev/sda2 98G 9.8G 84G 11% / +tmpfs 4.0G 0 4.0G 0% /dev/shm +tmpfs 5.0M 8.0K 5.0M 1% /run/lock +tmpfs 818M 148K 818M 1% /run/user/1000 +--------- Memory Usage --------- + total used free shared buff/cache available +Mem: 8172 1528 4550 37 2397 6644 +Swap: 4095 0 4095 +--------- CPU Load --------- + 21:30:21 up 1 day, 28 min, 1 user, load average: 0.07, 0.09, 0.09 +---- total running processes: 206 +----- Top 5 memeory-consuming processes ----- +USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND +joseph 1784 2.8 5.8 4094668 492048 ? Ssl Mar30 41:22 /usr/bin/gnome-shell +joseph 17392 0.1 3.1 1665480 263872 ? Sl 20:32 0:03 /usr/bin/nautilus --gapplication-service +joseph 2248 0.0 2.7 1358796 228068 ? Sl Mar30 0:40 /snap/snapd-desktop-integration/253/usr/bin/snapd-desktop-integration +joseph 1915 0.0 1.3 1138528 109936 ? Sl Mar30 0:01 /usr/libexec/evolution-data-server/evolution-alarm-notify +joseph 14478 0.0 1.1 1109756 98600 ? Sl 12:11 0:00 /usr/libexec/mutter-x11-frames +Backup created: ../backups/backup_20260331_213028.tar.gz +Old backups cleaned up diff --git a/log/backup.log b/log/backup.log new file mode 100644 index 0000000..2b4cb3b --- /dev/null +++ b/log/backup.log @@ -0,0 +1,8 @@ +Error: Directory does not exist +Usage: backup.sh +Backup created: ../backups/backup_20260331_201324.tar.gz +Old backups cleaned up +Backup created: ../backups/backup_20260331_212620.tar.gz +Old backups cleaned up +Backup created: ../backups/backup_20260331_213028.tar.gz +Old backups cleaned up diff --git a/log/file_manager.log b/log/file_manager.log new file mode 100644 index 0000000..57a5ccb --- /dev/null +++ b/log/file_manager.log @@ -0,0 +1,20 @@ +file created: sample.txt +file already exists! +total 12K +-rw-rw-r-- 1 joseph joseph 852 Mar 31 17:16 file_manager.sh +-rw-rw-r-- 1 joseph joseph 0 Mar 31 17:16 sample.txt +-rw-rw-r-- 1 joseph joseph 841 Mar 31 15:16 system_check.sh +-rw-rw-r-- 1 joseph joseph 646 Mar 31 14:12 user_info.sh +Renamed sample.txt to sample2.txt +Renamed sample.txt to sample2.txt +Renamed sample.txt to sample1.txt +Renamed sample.txt to sample1.txt +Renamed sample.txt to sample1.txt +file deleted: sample1.txt +total 24K +-rw-rw-r-- 1 joseph joseph 603 Mar 31 20:06 backup.sh +-rw-rw-r-- 1 joseph joseph 863 Mar 31 18:00 file_manager.sh +-rw-rw-r-- 1 joseph joseph 385 Mar 31 20:58 process_monitor.sh +-rw-rw-r-- 1 joseph joseph 626 Mar 31 21:23 run_all.sh +-rw-rw-r-- 1 joseph joseph 841 Mar 31 15:16 system_check.sh +-rw-rw-r-- 1 joseph joseph 646 Mar 31 14:12 user_info.sh diff --git a/log/process_monitor.log b/log/process_monitor.log new file mode 100644 index 0000000..cb15e9d --- /dev/null +++ b/log/process_monitor.log @@ -0,0 +1,12 @@ +nginx is stopped. Restarting... +nginx Restarted +ssh is stopped. Restarting... +ssh Restarted +docker is stopped. Restarting... +docker Restarted +nginx is stopped. Restarting... +nginx Restarted +ssh is stopped. Restarting... +ssh Restarted +docker is stopped. Restarting... +docker Restarted diff --git a/log/system_report_2026.log b/log/system_report_2026.log new file mode 100644 index 0000000..4dfc18f --- /dev/null +++ b/log/system_report_2026.log @@ -0,0 +1,66 @@ +===== SYSTEM REPORT ===== +--------- Disk Usage --------- +Filesystem Size Used Avail Use% Mounted on +tmpfs 818M 1.6M 816M 1% /run +/dev/sda2 98G 9.8G 84G 11% / +tmpfs 4.0G 0 4.0G 0% /dev/shm +tmpfs 5.0M 8.0K 5.0M 1% /run/lock +tmpfs 818M 160K 818M 1% /run/user/1000 +--------- Memory Usage --------- + total used free shared buff/cache available +Mem: 8172 1896 4203 71 2410 6275 +Swap: 4095 0 4095 +--------- CPU Load --------- + 15:19:38 up 18:17, 1 user, load average: 0.53, 0.12, 0.04 +---- total running processes: 204 +----- Top 5 memeory-consuming processes ----- +USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND +joseph 2528 0.1 6.6 1947756 559628 ? Sl Mar30 1:22 /usr/bin/nautilus --gapplication-service +joseph 1784 2.8 6.2 4129384 524168 ? Rsl Mar30 31:05 /usr/bin/gnome-shell +joseph 2834 0.0 3.9 1553160 332008 ? Sl Mar30 0:56 /snap/snap-store/1248/bin/snap-store +joseph 1915 0.0 1.3 1138528 109936 ? Sl Mar30 0:01 /usr/libexec/evolution-data-server/evolution-alarm-notify +joseph 14478 0.0 1.1 1109756 98600 ? Sl 12:11 0:00 /usr/libexec/mutter-x11-frames +===== SYSTEM REPORT ===== +--------- Disk Usage --------- +Filesystem Size Used Avail Use% Mounted on +tmpfs 818M 1.6M 816M 1% /run +/dev/sda2 98G 9.8G 84G 11% / +tmpfs 4.0G 0 4.0G 0% /dev/shm +tmpfs 5.0M 8.0K 5.0M 1% /run/lock +tmpfs 818M 148K 818M 1% /run/user/1000 +--------- Memory Usage --------- + total used free shared buff/cache available +Mem: 8172 1526 4552 37 2397 6645 +Swap: 4095 0 4095 +--------- CPU Load --------- + 21:26:20 up 1 day, 24 min, 1 user, load average: 0.01, 0.10, 0.11 +---- total running processes: 204 +----- Top 5 memeory-consuming processes ----- +USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND +joseph 1784 2.8 5.8 4098540 492048 ? Ssl Mar30 41:16 /usr/bin/gnome-shell +joseph 17392 0.1 3.1 1665480 263744 ? Sl 20:32 0:03 /usr/bin/nautilus --gapplication-service +joseph 2248 0.0 2.7 1358796 228068 ? Sl Mar30 0:40 /snap/snapd-desktop-integration/253/usr/bin/snapd-desktop-integration +joseph 1915 0.0 1.3 1138528 109936 ? Sl Mar30 0:01 /usr/libexec/evolution-data-server/evolution-alarm-notify +joseph 14478 0.0 1.1 1109756 98600 ? Sl 12:11 0:00 /usr/libexec/mutter-x11-frames +===== SYSTEM REPORT ===== +--------- Disk Usage --------- +Filesystem Size Used Avail Use% Mounted on +tmpfs 818M 1.6M 816M 1% /run +/dev/sda2 98G 9.8G 84G 11% / +tmpfs 4.0G 0 4.0G 0% /dev/shm +tmpfs 5.0M 8.0K 5.0M 1% /run/lock +tmpfs 818M 148K 818M 1% /run/user/1000 +--------- Memory Usage --------- + total used free shared buff/cache available +Mem: 8172 1528 4550 37 2397 6644 +Swap: 4095 0 4095 +--------- CPU Load --------- + 21:30:21 up 1 day, 28 min, 1 user, load average: 0.07, 0.09, 0.09 +---- total running processes: 206 +----- Top 5 memeory-consuming processes ----- +USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND +joseph 1784 2.8 5.8 4094668 492048 ? Ssl Mar30 41:22 /usr/bin/gnome-shell +joseph 17392 0.1 3.1 1665480 263872 ? Sl 20:32 0:03 /usr/bin/nautilus --gapplication-service +joseph 2248 0.0 2.7 1358796 228068 ? Sl Mar30 0:40 /snap/snapd-desktop-integration/253/usr/bin/snapd-desktop-integration +joseph 1915 0.0 1.3 1138528 109936 ? Sl Mar30 0:01 /usr/libexec/evolution-data-server/evolution-alarm-notify +joseph 14478 0.0 1.1 1109756 98600 ? Sl 12:11 0:00 /usr/libexec/mutter-x11-frames diff --git a/log/user_info.log b/log/user_info.log new file mode 100644 index 0000000..b3c1687 --- /dev/null +++ b/log/user_info.log @@ -0,0 +1,2 @@ +Hello Joseph from 9ja! You are an Adult. +Hello Joseph from 9ja! You are an Adult. diff --git a/scripts/.user_info.sh.swn b/scripts/.user_info.sh.swn new file mode 100644 index 0000000..e1d2077 Binary files /dev/null and b/scripts/.user_info.sh.swn differ diff --git a/scripts/.user_info.sh.swo b/scripts/.user_info.sh.swo new file mode 100644 index 0000000..38abcf7 Binary files /dev/null and b/scripts/.user_info.sh.swo differ diff --git a/scripts/.user_info.sh.swp b/scripts/.user_info.sh.swp new file mode 100644 index 0000000..a1f7308 Binary files /dev/null and b/scripts/.user_info.sh.swp differ diff --git a/scripts/backup.sh b/scripts/backup.sh new file mode 100644 index 0000000..79d632f --- /dev/null +++ b/scripts/backup.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +SOURCE_DIR=$1 +BACKUP_DIR="../backups" +LOG_FILE="../log/backup.log" + +if [[ ! -d "$SOURCE_DIR" ]]; then + echo "Error: Directory does not exist" | tee -a "$LOG_FILE" + + echo "Usage: $0 " | 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" "$SOURCE_DIR" + + echo "Backup created: $BACKUP_FILE" | tee -a "$LOG_FILE" + +# Keep only last 5 backups + + ls -t $BACKUP_DIR/backup_*.tar.gz | tail -n +6 | xargs -r rm + + echo "Old backups cleaned up" | tee -a "$LOG_FILE" + diff --git a/scripts/file_manager.sh b/scripts/file_manager.sh new file mode 100644 index 0000000..711e444 --- /dev/null +++ b/scripts/file_manager.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +LOG_FILE="../log/file_manager.log" +ACTION=$1 +FILE=$2 + +case "$ACTION" in + create) + if [[ -f "$FILE" ]]; then + echo "file already exists!" | tee -a "$LOG_FILE" + else + touch "$FILE" + echo "file created: $FILE" | tee -a "$LOG_FILE" + fi + ;; + delete) + + if [[ -f "$FILE" ]]; then + rm "$FILE" + echo "file deleted: $FILE" | tee -a "$LOG_FILE" + else + echo "file not found!" | tee -a "$LOG_FILE" + fi + ;; + + list) + ls -lh | tee -a "$LOG_FILE" + ;; + + rename) + NEW_NAME=$3 + 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 "Usage: $0 {create|delete|list|rename} filename?" | tee -a "$LOG_FILE" + ;; + esac + diff --git a/scripts/process_monitor.sh b/scripts/process_monitor.sh new file mode 100644 index 0000000..91338e4 --- /dev/null +++ b/scripts/process_monitor.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +LOG_FILE="../log/process_monitor.log" +services=("nginx" "ssh" "docker") + +for service in "${services[@]}"; do + if pgrep -x "$service" > /dev/null; + then + echo "$service is Running" | tee -a "$LOG_FILE" + else + echo "$service is stopped. Restarting..." | tee -a "$LOG_FILE" + +# simulate restart + echo "$service Restarted" | tee -a "$LOG_FILE" + + fi +done diff --git a/scripts/run_all.sh b/scripts/run_all.sh new file mode 100644 index 0000000..54b320b --- /dev/null +++ b/scripts/run_all.sh @@ -0,0 +1,38 @@ +#!/bin/bash +set -euo pipefail + +LOG_FILE="../log/app.log" + +run_all() { + bash file_manager.sh list + bash system_check.sh + bash backup.sh . + bash process_monitor.sh + bash user_info.sh + +} + +menu() { + echo "1. Run all" + echo "2. System check" + echo "3. Backup" + echo "4. Exit" + +} + + while true; do + menu + read -p "choose option: " choice + + case $choice in + 1) run_all | tee -a "$LOG_FILE" + ;; + 2) bash system_check.sh | tee -a "$LOG_FILE" + ;; + 3) bash backup.sh . | tee -a "$LOG_FILE" + ;; + 4) exit 0 + ;; + *) echo "Invalid option" ;; + esac +done diff --git a/scripts/simple1 b/scripts/simple1 new file mode 100644 index 0000000..7a693aa --- /dev/null +++ b/scripts/simple1 @@ -0,0 +1,3 @@ +#!/bin/bash + + diff --git a/scripts/system_check.sh b/scripts/system_check.sh new file mode 100644 index 0000000..916f1d6 --- /dev/null +++ b/scripts/system_check.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +DATE=$(date +"%Y") +LOG_FILE="../log/system_report_$DATE.log" + + echo "===== SYSTEM REPORT =====" | tee -a "$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 Warnig +USAGE=$(df / | awk 'NR==2 {print $5}' | sed 's/%//') + if (( USAGE > 80 )); then + echo "WARNING: Disk usage is above 80%" | tee -a "$LOG_FILE" + fi + +# process count +echo "---- total running processes: $(ps aux | wc -l)" | tee -a "$LOG_FILE" + +# top 5 memory-consuming processes + echo "----- Top 5 memeory-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 new file mode 100644 index 0000000..6287c68 --- /dev/null +++ b/scripts/user_info.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +LOG_FILE="../log/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 +fi + +if [[ ! "$age" =~ ^[0-9]+$ ]]; then + echo "Error: Age must be numeric" | 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 + +message="Hello $name from $country! You are an $category." + echo "$message" | tee -a "$LOG_FILE" + +