diff --git a/backups/backup_20260402_151406.tar.gz b/backups/backup_20260402_151406.tar.gz new file mode 100644 index 0000000..44c460c Binary files /dev/null and b/backups/backup_20260402_151406.tar.gz differ diff --git a/backups/backup_20260402_152227.tar.gz b/backups/backup_20260402_152227.tar.gz new file mode 100644 index 0000000..e32efee Binary files /dev/null and b/backups/backup_20260402_152227.tar.gz differ diff --git a/logs/app.log b/logs/app.log new file mode 100644 index 0000000..cb9463e --- /dev/null +++ b/logs/app.log @@ -0,0 +1,78 @@ +total 24K +-rw-r--r-- 1 the_godbeing the_godbeing 612 Apr 2 15:13 backup.sh +-rw-r--r-- 1 the_godbeing the_godbeing 925 Apr 2 14:55 file_manager.sh +-rw-r--r-- 1 the_godbeing the_godbeing 385 Apr 2 15:17 process_monitor.sh +-rw-r--r-- 1 the_godbeing the_godbeing 597 Apr 2 15:20 run_all.sh +-rw-r--r-- 1 the_godbeing the_godbeing 839 Apr 2 14:31 system_check.sh +-rw-r--r-- 1 the_godbeing the_godbeing 671 Apr 2 11:19 user_info.sh +===== SYSTEM REPORT ===== +---------- Disk Usage ---------- +Filesystem Size Used Avail Use% Mounted on +none 3.9G 0 3.9G 0% /usr/lib/modules/6.6.87.2-microsoft-standard-WSL2 +none 3.9G 4.0K 3.9G 1% /mnt/wsl +drivers 238G 101G 137G 43% /usr/lib/wsl/drivers +/dev/sdd 1007G 1.6G 955G 1% / +none 3.9G 112K 3.9G 1% /mnt/wslg +none 3.9G 0 3.9G 0% /usr/lib/wsl/lib +rootfs 3.9G 2.7M 3.9G 1% /init +none 3.9G 488K 3.9G 1% /run +none 3.9G 0 3.9G 0% /run/lock +none 3.9G 0 3.9G 0% /run/shm +none 3.9G 76K 3.9G 1% /mnt/wslg/versions.txt +none 3.9G 76K 3.9G 1% /mnt/wslg/doc +C:\ 238G 101G 137G 43% /mnt/c +tmpfs 789M 8.0K 789M 1% /run/user/1000 +---------- Memory Usage ---------- + total used free shared buff/cache available +Mem: 7881 318 7401 3 161 7405 +Swap: 2048 0 2048 +---------- CPU Load ---------- + 15:22:27 up 4:50, 1 user, load average: 0.00, 0.00, 0.00 +----- Total running processes: 35 +---------- Top 5 memory-consuming processes ---------- +USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND +root 218 0.0 0.2 107164 21632 ? Ssl 10:33 0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal +root 808 0.0 0.2 293004 19968 ? Ssl 10:36 0:00 /usr/libexec/packagekitd +root 186 0.0 0.2 30136 18560 ? Ss 10:33 0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers +root 63 0.0 0.1 47828 15104 ? S +Backup created: ../backups/backup_20260402_151406.tar.gz +Old backups cleaned up +Backup created: ../backups/backup_20260402_152227.tar.gz +Old backups cleaned up diff --git a/logs/file_manager.log b/logs/file_manager.log new file mode 100644 index 0000000..9a2e466 --- /dev/null +++ b/logs/file_manager.log @@ -0,0 +1,15 @@ +File created: sample.txt +total 12K +-rw-r--r-- 1 the_godbeing the_godbeing 925 Apr 2 14:55 file_manager.sh +-rw-r--r-- 1 the_godbeing the_godbeing 0 Apr 2 14:56 sample.txt +-rw-r--r-- 1 the_godbeing the_godbeing 839 Apr 2 14:31 system_check.sh +-rw-r--r-- 1 the_godbeing the_godbeing 671 Apr 2 11:19 user_info.sh +Renamed sample.txt to sample1.txt +File deleted: sample1.txt +total 24K +-rw-r--r-- 1 the_godbeing the_godbeing 612 Apr 2 15:13 backup.sh +-rw-r--r-- 1 the_godbeing the_godbeing 925 Apr 2 14:55 file_manager.sh +-rw-r--r-- 1 the_godbeing the_godbeing 385 Apr 2 15:17 process_monitor.sh +-rw-r--r-- 1 the_godbeing the_godbeing 597 Apr 2 15:20 run_all.sh +-rw-r--r-- 1 the_godbeing the_godbeing 839 Apr 2 14:31 system_check.sh +-rw-r--r-- 1 the_godbeing the_godbeing 671 Apr 2 11:19 user_info.sh diff --git a/logs/process_monitor.log b/logs/process_monitor.log new file mode 100644 index 0000000..49e0ec0 --- /dev/null +++ b/logs/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/logs/system_report_2026.log b/logs/system_report_2026.log new file mode 100644 index 0000000..a04d1a8 --- /dev/null +++ b/logs/system_report_2026.log @@ -0,0 +1,93 @@ +===== SYSTEM REPORT ===== +---------- Disk Usage ---------- +Filesystem Size Used Avail Use% Mounted on +none 3.9G 0 3.9G 0% /usr/lib/modules/6.6.87.2-microsoft-standard-WSL2 +none 3.9G 4.0K 3.9G 1% /mnt/wsl +drivers 238G 101G 137G 43% /usr/lib/wsl/drivers +/dev/sdd 1007G 1.6G 955G 1% / +none 3.9G 112K 3.9G 1% /mnt/wslg +none 3.9G 0 3.9G 0% /usr/lib/wsl/lib +rootfs 3.9G 2.7M 3.9G 1% /init +none 3.9G 488K 3.9G 1% /run +none 3.9G 0 3.9G 0% /run/lock +none 3.9G 0 3.9G 0% /run/shm +none 3.9G 76K 3.9G 1% /mnt/wslg/versions.txt +none 3.9G 76K 3.9G 1% /mnt/wslg/doc +C:\ 238G 101G 137G 43% /mnt/c +tmpfs 789M 8.0K 789M 1% /run/user/1000 +---------- Memory Usage ---------- + total used free shared buff/cache available +Mem: 7881 323 7398 3 159 7400 +Swap: 2048 0 2048 +---------- CPU Load ---------- + 14:32:08 up 4:01, 1 user, load average: 0.00, 0.00, 0.00 +----- Total running processes: 37 +---------- Top 5 memory-consuming processes ---------- +USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND +root 218 0.0 0.2 107164 21632 ? Ssl 10:31 0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal +root 808 0.0 0.2 293004 19968 ? Ssl 10:35 0:00 /usr/libexec/packagekitd +root 186 0.0 0.2 30136 18560 ? Ss 10:31 0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers +root 63 0.0 0.1 47828 15104 ? S" | 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..33da7a9 --- /dev/null +++ b/scripts/file_manager.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +LOG_FILE="../logs/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 filename?" | tee -a "$LOG_FILE" + ;; +esac diff --git a/scripts/process_monitor.sh b/scripts/process_monitor.sh new file mode 100644 index 0000000..7d6f89d --- /dev/null +++ b/scripts/process_monitor.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +LOG_FILE="../logs/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..099dd20 --- /dev/null +++ b/scripts/run_all.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -euo pipefail + +LOG_FILE="../logs/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/system_check.sh b/scripts/system_check.sh new file mode 100644 index 0000000..3aa79a4 --- /dev/null +++ b/scripts/system_check.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +DATE=$(date +"%Y") +LOG_FILE="../logs/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 warning +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 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 new file mode 100644 index 0000000..82ccb6e --- /dev/null +++ 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 + 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"