diff --git a/Scripts/backup.sh b/Scripts/backup.sh new file mode 100755 index 0000000..c9b86ab --- /dev/null +++ b/Scripts/backup.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +BACKUP_DIR="backups" +LOG_DIR="logs" +LOG_FILE="$LOG_DIR/backup.log" + +mkdir -p "$BACKUP_DIR" +mkdir -p "$LOG_DIR" + +log_action() { + echo "$(date '+%Y-%m-%d %H:%M:%S') | $1" >> "$LOG_FILE" +} + +if [[ -z "$1" ]]; then + echo "Usage: $0 " + exit 1 +fi + +SOURCE_DIR="$1" + +# Validate directory existence +if [[ ! -d "$SOURCE_DIR" ]]; then + echo "Error: Directory does not exist -> $SOURCE_DIR" + log_action "BACKUP FAILED - invalid directory: $SOURCE_DIR" + exit 1 +fi + +# Generate timestamp +TIMESTAMP=$(date '+%Y%m%d_%H%M%S') +BASENAME=$(basename "$SOURCE_DIR") +BACKUP_FILE="backup_${BASENAME}_${TIMESTAMP}.tar.gz" +BACKUP_PATH="$BACKUP_DIR/$BACKUP_FILE" + +# Create compressed backup +tar -czf "$BACKUP_PATH" -C "$(dirname "$SOURCE_DIR")" "$BASENAME" + +if [[ $? -eq 0 ]]; then + echo "Backup created: $BACKUP_PATH" + log_action "BACKUP SUCCESS - $SOURCE_DIR -> $BACKUP_FILE" +else + echo "Backup failed for $SOURCE_DIR" + log_action "BACKUP FAILED - tar error for $SOURCE_DIR" + exit 1 +fi + +# Retention policy: keep only last 5 backups +cd "$BACKUP_DIR" || exit + +ls -1t backup_*.tar.gz 2>/dev/null | tail -n +6 | while read -r old_backup; do + rm -f "$old_backup" + log_action "RETENTION DELETE - removed $old_backup" +done diff --git a/Scripts/file_manager.sh b/Scripts/file_manager.sh new file mode 100755 index 0000000..2355390 --- /dev/null +++ b/Scripts/file_manager.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +LOG_DIR="logs" +LOG_FILE="$LOG_DIR/file_manager.log" + +mkdir -p "$LOG_DIR" + +log_action() { + echo "$(date '+%Y-%m-%d %H:%M:%S') | $1" >> "$LOG_FILE" +} + +create_file() { + local file=$1 + + if [[ -z "$file" ]]; then + echo "Error: No filename provided" + return 1 + fi + + if [[ -f "$file" ]]; then + echo "Blocked: File '$file' already exists" + log_action "CREATE FAILED - $file already exists" + return 1 + fi + + touch "$file" + echo "Created: $file" + log_action "CREATE SUCCESS - $file created" +} + +delete_file() { + local file=$1 + + if [[ -z "$file" ]]; then + echo "Error: No filename provided" + return 1 + fi + + if [[ ! -f "$file" ]]; then + echo "Blocked: File '$file' does not exist" + log_action "DELETE FAILED - $file not found" + return 1 + fi + + rm "$file" + echo "Deleted: $file" + log_action "DELETE SUCCESS - $file removed" +} + +list_files() { + echo "Current directory file listing:" + ls -lh + log_action "LIST EXECUTED" +} + +rename_file() { + local old_name=$1 + local new_name=$2 + + if [[ -z "$old_name" || -z "$new_name" ]]; then + echo "Error: Provide old and new filenames" + return 1 + fi + + if [[ ! -f "$old_name" ]]; then + echo "Blocked: Source file does not exist" + log_action "RENAME FAILED - $old_name not found" + return 1 + fi + + if [[ -f "$new_name" ]]; then + echo "Blocked: Target file already exists" + log_action "RENAME FAILED - $new_name already exists" + return 1 + fi + + mv "$old_name" "$new_name" + echo "Renamed: $old_name -> $new_name" + log_action "RENAME SUCCESS - $old_name to $new_name" +} + +case "$1" in + create) + create_file "$2" + ;; + delete) + delete_file "$2" + ;; + list) + list_files + ;; + rename) + rename_file "$2" "$3" + ;; + *) + echo "Usage: $0 {create|delete|list|rename}" + exit 1 + ;; +esac diff --git a/Scripts/key pair b/Scripts/key pair new file mode 100644 index 0000000..2ff55b2 --- /dev/null +++ b/Scripts/key pair @@ -0,0 +1,7 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW +QyNTUxOQAAACBWsMv+GZz/wr6N4wnJ+0jyfzt6lKqhqFOQQUobjLR71AAAAJht4599beOf +fQAAAAtzc2gtZWQyNTUxOQAAACBWsMv+GZz/wr6N4wnJ+0jyfzt6lKqhqFOQQUobjLR71A +AAAED+Ek4kOU5bHL/VrE1gpxNV7gQEIu2mF+7kaR0TZvH9nFawy/4ZnP/Cvo3jCcn7SPJ/ +O3qUqqGoU5BBShuMtHvUAAAAEmlnd2VqNDA4QGdtYWlsLmNvbQECAw== +-----END OPENSSH PRIVATE KEY----- diff --git a/Scripts/key pair.pub b/Scripts/key pair.pub new file mode 100644 index 0000000..38564ae --- /dev/null +++ b/Scripts/key pair.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFawy/4ZnP/Cvo3jCcn7SPJ/O3qUqqGoU5BBShuMtHvU igwej408@gmail.com diff --git a/Scripts/logs/file_manager.log b/Scripts/logs/file_manager.log new file mode 100644 index 0000000..8af6c17 --- /dev/null +++ b/Scripts/logs/file_manager.log @@ -0,0 +1 @@ +2026-04-16 19:26:41 | LIST EXECUTED diff --git a/Scripts/logs/service_monitor.log b/Scripts/logs/service_monitor.log new file mode 100644 index 0000000..58c47ab --- /dev/null +++ b/Scripts/logs/service_monitor.log @@ -0,0 +1,3 @@ +2026-04-16 19:32:21 | nginx STATUS - STOPPED +2026-04-16 19:32:21 | nginx ACTION - RESTART INITIATED +2026-04-16 19:32:22 | nginx STATUS - RESTART SIMULATED diff --git a/Scripts/logs/system_report_2026-04-16.log b/Scripts/logs/system_report_2026-04-16.log new file mode 100644 index 0000000..f07e3e7 --- /dev/null +++ b/Scripts/logs/system_report_2026-04-16.log @@ -0,0 +1,47 @@ +===================================== + System Health Report + Date: Thu Apr 16 19:19:39 WAT 2026 +===================================== + +>>> Disk Usage (df -h) +Filesystem Size Used Avail Use% Mounted on +none 1.5G 0 1.5G 0% /usr/lib/modules/6.6.87.2-microsoft-standard-WSL2 +none 1.5G 4.0K 1.5G 1% /mnt/wsl +none 1.5G 556K 1.5G 1% /mnt/wsl/docker-desktop/shared-sockets/host-services +/dev/sdd 136M 71M 54M 57% /mnt/wsl/docker-desktop/docker-desktop-user-distro +/dev/loop0 813M 813M 0 100% /mnt/wsl/docker-desktop/cli-tools +drivers 238G 121G 118G 51% /usr/lib/wsl/drivers +/dev/sdf 1007G 2.1G 954G 1% / +none 1.5G 76K 1.5G 1% /mnt/wslg +none 1.5G 0 1.5G 0% /usr/lib/wsl/lib +rootfs 1.4G 2.7M 1.4G 1% /init +none 1.5G 544K 1.5G 1% /run +none 1.5G 0 1.5G 0% /run/lock +none 1.5G 0 1.5G 0% /run/shm +none 1.5G 76K 1.5G 1% /mnt/wslg/versions.txt +none 1.5G 76K 1.5G 1% /mnt/wslg/doc +C:\ 238G 121G 118G 51% /mnt/c +tmpfs 288M 20K 288M 1% /run/user/1000 +tmpfs 288M 20K 288M 1% /run/user/0 +C:\Program Files\Docker\Docker\resources 238G 121G 118G 51% /Docker/host + + +>>> Memory Usage (free -m) + total used free shared buff/cache available +Mem: 2874 644 1842 4 467 2230 +Swap: 1024 1 1022 + + +>>> CPU Load (uptime) + 19:19:39 up 1:29, 2 users, load average: 0.00, 0.00, 0.00 + +Total Running Processes: 36 + +>>> Top 5 Memory-Consuming Processes + PID COMMAND %MEM + 599 docker-desktop- 0.9 + 209 unattended-upgr 0.7 + 58 systemd-journal 0.5 + 153 systemd-resolve 0.4 + 178 wsl-pro-service 0.4 + diff --git a/Scripts/logs/user_info.log b/Scripts/logs/user_info.log new file mode 100644 index 0000000..8abc84d --- /dev/null +++ b/Scripts/logs/user_info.log @@ -0,0 +1,4 @@ +--------------------------------- +Hello ki from rf +Age Category: Adult +--------------------------------- diff --git a/Scripts/process_monitor.sh b/Scripts/process_monitor.sh new file mode 100755 index 0000000..eb8f76b --- /dev/null +++ b/Scripts/process_monitor.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +LOG_DIR="logs" +LOG_FILE="$LOG_DIR/service_monitor.log" + +mkdir -p "$LOG_DIR" + +log_action() { + echo "$(date '+%Y-%m-%d %H:%M:%S') | $1" >> "$LOG_FILE" +} + +# Define service portfolio (operational baseline) +services=("nginx" "ssh" "docker") + +check_and_handle_service() { + local service=$1 + + if [[ -z "$service" ]]; then + echo "No service provided" + return 1 + fi + + # Check if process is running + if pgrep -x "$service" > /dev/null; then + echo "$service: Running" + log_action "$service STATUS - RUNNING" + else + echo "$service: Stopped" + log_action "$service STATUS - STOPPED" + + # Simulated restart logic + echo "$service: Restarting..." + log_action "$service ACTION - RESTART INITIATED" + + # Attempt real restart if systemctl exists, otherwise simulate + if command -v systemctl >/dev/null 2>&1; then + systemctl restart "$service" 2>/dev/null + else + sleep 1 + fi + + # Re-check status after restart attempt + if pgrep -x "$service" > /dev/null; then + echo "$service: Restarted" + log_action "$service STATUS - RESTARTED SUCCESS" + else + echo "$service: Restart simulated (not active)" + log_action "$service STATUS - RESTART SIMULATED" + fi + fi +} + +# Execution mode +if [[ -n "$1" ]]; then + check_and_handle_service "$1" +else + # Batch monitoring mode + for svc in "${services[@]}"; do + check_and_handle_service "$svc" + done +fi diff --git a/Scripts/system_check.sh b/Scripts/system_check.sh new file mode 100755 index 0000000..69ace7c --- /dev/null +++ b/Scripts/system_check.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +# ----------------------------- +# Configuration +# ----------------------------- +LOG_DIR="logs" +DATE=$(date +"%Y-%m-%d") +LOG_FILE="$LOG_DIR/system_report_${DATE}.log" +DISK_THRESHOLD=80 + +mkdir -p "$LOG_DIR" + +# ----------------------------- +# Header +# ----------------------------- +{ +echo "=====================================" +echo " System Health Report" +echo " Date: $(date)" +echo "=====================================" +echo +} >> "$LOG_FILE" + +# ----------------------------- +# Disk Usage +# ----------------------------- +{ +echo ">>> Disk Usage (df -h)" +df -h +echo +} >> "$LOG_FILE" + +# Warn if disk usage exceeds threshold +DISK_ALERT=$(df -h / | awk 'NR==2 {gsub("%","",$5); print $5}') +if (( DISK_ALERT > DISK_THRESHOLD )); then + echo "WARNING: Disk usage exceeds ${DISK_THRESHOLD}% (Current: ${DISK_ALERT}%)" >> "$LOG_FILE" +fi + +# ----------------------------- +# Memory Usage +# ----------------------------- +{ +echo +echo ">>> Memory Usage (free -m)" +free -m +echo +} >> "$LOG_FILE" + +# ----------------------------- +# CPU Load +# ----------------------------- +{ +echo +echo ">>> CPU Load (uptime)" +uptime +echo +} >> "$LOG_FILE" + +# ----------------------------- +# Process Count +# ----------------------------- +PROCESS_COUNT=$(ps -e --no-headers | wc -l) +echo "Total Running Processes: $PROCESS_COUNT" >> "$LOG_FILE" + +# ----------------------------- +# Top 5 Memory-Consuming Processes +# ----------------------------- +{ +echo +echo ">>> Top 5 Memory-Consuming Processes" +ps -eo pid,comm,%mem --sort=-%mem | head -n 6 +echo +} >> "$LOG_FILE" + +# ----------------------------- +# Completion Notice +# ----------------------------- +echo "Report saved to $LOG_FILE" diff --git a/Scripts/user_info.sh b/Scripts/user_info.sh new file mode 100755 index 0000000..e0312d2 --- /dev/null +++ b/Scripts/user_info.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +LOG_DIR="logs" +LOG_FILE="$LOG_DIR/user_info.log" + +# Ensure log directory exists +mkdir -p "$LOG_DIR" + +# ----------------------------- +# User Input (Controlled Intake) +# ----------------------------- + +# Name validation +while true; do + read -p "Enter your name: " NAME + if [[ -n "$NAME" ]]; then + break + else + echo "Name is required. Please try again." + fi +done + +# Age validation (numeric only) +while true; do + read -p "Enter your age: " AGE + if [[ "$AGE" =~ ^[0-9]+$ ]]; then + break + else + echo "Invalid age. Please enter a numeric value." + fi +done + +# Country validation +while true; do + read -p "Enter your country: " COUNTRY + if [[ -n "$COUNTRY" ]]; then + break + else + echo "Country is required. Please try again." + fi +done + +# ----------------------------- +# Business Logic (Classification) +# ----------------------------- + +if (( AGE < 18 )); then + CATEGORY="Minor" +elif (( AGE <= 65 )); then + CATEGORY="Adult" +else + CATEGORY="Senior" +fi + +# ----------------------------- +# Output (Console + Log) +# ----------------------------- + +OUTPUT=$(cat <> "$LOG_FILE"