Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added backups/backup_scripts_20260401_020415.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions logs/backup.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[2026-04-01 02:04:15] Backup successful: 'scripts' -> 'backups/backup_scripts_20260401_020415.tar.gz'
4 changes: 4 additions & 0 deletions logs/file_manager.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[2026-04-01 02:04:13] Created file: 'temp_test.txt'
[2026-04-01 02:04:13] Renamed 'temp_test.txt' to 'temp_test_renamed.txt'
[2026-04-01 02:04:13] Listed directory: '.'
[2026-04-01 02:04:13] Deleted: 'temp_test_renamed.txt'
1 change: 1 addition & 0 deletions logs/process_monitor.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[2026-04-01 02:04:15] Process 'bash' status: Running
54 changes: 54 additions & 0 deletions logs/system_report_20260401_020414.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
System Check Report - Wed 1 Apr 2026 02:04:14 WAT
========================================

[Disk Usage]
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk3s1s1 460Gi 12Gi 20Gi 37% 455k 211M 0% /
devfs 218Ki 218Ki 0Bi 100% 754 0 100% /dev
/dev/disk3s6 460Gi 7.0Gi 20Gi 26% 7 211M 0% /System/Volumes/VM
/dev/disk3s2 460Gi 8.1Gi 20Gi 29% 1.4k 211M 0% /System/Volumes/Preboot
/dev/disk3s4 460Gi 3.0Mi 20Gi 1% 66 211M 0% /System/Volumes/Update
/dev/disk1s2 500Mi 6.0Mi 483Mi 2% 1 4.9M 0% /System/Volumes/xarts
/dev/disk1s1 500Mi 5.8Mi 483Mi 2% 31 4.9M 0% /System/Volumes/iSCPreboot
/dev/disk1s3 500Mi 884Ki 483Mi 1% 63 4.9M 0% /System/Volumes/Hardware
/dev/disk3s5 460Gi 412Gi 20Gi 96% 6.7M 211M 3% /System/Volumes/Data
map auto_home 0Bi 0Bi 0Bi 100% 0 0 - /System/Volumes/Data/home
/dev/disk5s1 16Gi 15Gi 471Mi 98% 498k 4.8M 9% /Library/Developer/CoreSimulator/Volumes/iOS_21A342
/dev/disk7s1 17Gi 16Gi 438Mi 98% 608k 4.5M 12% /Library/Developer/CoreSimulator/Volumes/iOS_23D8133
/dev/disk9s1 385Mi 308Mi 75Mi 81% 552 768k 0% /Volumes/Redis Insight 2.70.1-arm64
/Applications/Pi.app/Wrapper 460Gi 411Gi 17Gi 96% 6.7M 180M 4% /private/var/folders/wb/mzs_c3rs3dxg3ny4_qjb8jr80000gn/X/3D6AE059-CE29-57AE-83C8-F52C55B49D47

[Memory Usage]
Mach Virtual Memory Statistics: (page size of 16384 bytes)
Pages free: 3607.
Pages active: 87622.
Pages inactive: 82929.
Pages speculative: 3702.
Pages throttled: 0.
Pages wired down: 128762.
Pages purgeable: 116.
"Translation faults": 8593002225.
Pages copy-on-write: 133987569.
Pages zero filled: 1387209860.
Pages reactivated: 3309616018.
Pages purged: 195006250.
File-backed pages: 64104.
Anonymous pages: 110149.
Pages stored in compressor: 1127316.
Pages occupied by compressor: 180828.
Decompressions: 4188604159.
Compressions: 4461894951.
Pageins: 388002623.
Pageouts: 8041712.
Swapins: 175807753.
Swapouts: 184713802.

[CPU Load]
2:04 up 15 days, 17:21, 3 users, load averages: 2.29 2.17 3.60

[Disk Usage Warnings (>80%)]
WARNING: /dev/disk3s5 is at 96% usage (mount: /System/Volumes/Data)\nWARNING: /dev/disk5s1 is at 98% usage (mount: /Library/Developer/CoreSimulator/Volumes/iOS_21A342)\nWARNING: /dev/disk7s1 is at 98% usage (mount: /Library/Developer/CoreSimulator/Volumes/iOS_23D8133)\nWARNING: /dev/disk9s1 is at 81% usage (mount: /Volumes/Redis)\nWARNING: /Applications/Pi.app/Wrapper is at 96% usage (mount: /private/var/folders/wb/mzs_c3rs3dxg3ny4_qjb8jr80000gn/X/3D6AE059-CE29-57AE-83C8-F52C55B49D47)\n
[Total Running Processes]
512

[Top 5 Memory-Consuming Processes]
1 change: 1 addition & 0 deletions logs/user_info.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[2026-04-01 02:04:12] Hello, Alice from India. You are 22 years old and categorized as: Adult.
98 changes: 98 additions & 0 deletions run_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash

set -euo pipefail

LOG_DIR="logs"
LOG_FILE="$LOG_DIR/app.log"

mkdir -p "$LOG_DIR"

timestamp() {
date "+%Y-%m-%d %H:%M:%S"
}

log_action() {
echo "[$(timestamp)] $1" | tee -a "$LOG_FILE"
}

run_system_check() {
log_action "Running system_check.sh"
if ./scripts/system_check.sh; then
log_action "system_check.sh completed successfully"
else
log_action "system_check.sh failed"
fi
}

run_backup() {
read -r -p "Enter directory path to back up: " backup_dir
log_action "Running backup.sh for '$backup_dir'"
if ./scripts/backup.sh "$backup_dir"; then
log_action "backup.sh completed successfully"
else
log_action "backup.sh failed"
fi
}

run_all() {
log_action "Running all core scripts"

if ./scripts/user_info.sh; then
log_action "user_info.sh completed successfully"
else
log_action "user_info.sh failed"
fi

run_system_check

if ./scripts/file_manager.sh list .; then
log_action "file_manager.sh completed successfully"
else
log_action "file_manager.sh failed"
fi

read -r -p "Enter directory path for backup in 'Run all': " backup_dir
if ./scripts/backup.sh "$backup_dir"; then
log_action "backup.sh completed successfully"
else
log_action "backup.sh failed"
fi
}

show_menu() {
echo
echo "===== DevOps Bash Toolkit ====="
echo "1. Run all"
echo "2. System check"
echo "3. Backup"
echo "4. Exit"
echo "==============================="
}

main() {
while true; do
show_menu
read -r -p "Choose an option [1-4]: " choice

case "$choice" in
1)
run_all
;;
2)
run_system_check
;;
3)
run_backup
;;
4)
log_action "Exiting application"
exit 0
;;
*)
echo "Invalid choice. Please select 1-4."
;;
esac
done
}

main
44 changes: 44 additions & 0 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

LOG_DIR="logs"
BACKUP_DIR="backups"
LOG_FILE="$LOG_DIR/backup.log"

mkdir -p "$LOG_DIR" "$BACKUP_DIR"

timestamp() {
date "+%Y-%m-%d %H:%M:%S"
}

log_action() {
echo "[$(timestamp)] $1" | tee -a "$LOG_FILE"
}

source_dir="$1"

if [[ -z "$source_dir" ]]; then
log_action "Backup failed: No directory provided. Usage: $0 <directory>"
exit 1
fi

if [[ ! -d "$source_dir" ]]; then
log_action "Backup failed: '$source_dir' is not a valid directory."
exit 1
fi

source_base="$(basename "$source_dir")"
archive_name="backup_${source_base}_$(date +%Y%m%d_%H%M%S).tar.gz"
archive_path="$BACKUP_DIR/$archive_name"

if tar -czf "$archive_path" -C "$(dirname "$source_dir")" "$source_base"; then
log_action "Backup successful: '$source_dir' -> '$archive_path'"
else
log_action "Backup failed while creating archive for '$source_dir'"
exit 1
fi

# Keep only the 5 most recent backups.
ls -1t "$BACKUP_DIR"/*.tar.gz 2>/dev/null | awk 'NR>5' | while IFS= read -r old_backup; do
rm -f "$old_backup"
log_action "Removed old backup: '$old_backup'"
done
119 changes: 119 additions & 0 deletions scripts/file_manager.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env bash

LOG_DIR="logs"
LOG_FILE="$LOG_DIR/file_manager.log"

mkdir -p "$LOG_DIR"

timestamp() {
date "+%Y-%m-%d %H:%M:%S"
}

log_action() {
echo "[$(timestamp)] $1" >> "$LOG_FILE"
}

usage() {
echo "Usage: $0 {create|delete|list|rename} [args]"
echo "Examples:"
echo " $0 create file.txt"
echo " $0 delete file.txt"
echo " $0 list ."
echo " $0 rename old.txt new.txt"
}

command="$1"

case "$command" in
create)
file="$2"
if [[ -z "$file" ]]; then
echo "Error: Please provide a filename to create."
usage
exit 1
fi

if [[ -e "$file" ]]; then
msg="Create failed: '$file' already exists."
echo "$msg"
log_action "$msg"
exit 1
fi

touch "$file"
msg="Created file: '$file'"
echo "$msg"
log_action "$msg"
;;

delete)
file="$2"
if [[ -z "$file" ]]; then
echo "Error: Please provide a filename to delete."
usage
exit 1
fi

if [[ ! -e "$file" ]]; then
msg="Delete failed: '$file' does not exist."
echo "$msg"
log_action "$msg"
exit 1
fi

rm -f "$file"
msg="Deleted: '$file'"
echo "$msg"
log_action "$msg"
;;

list)
target="${2:-.}"
if [[ ! -d "$target" ]]; then
msg="List failed: '$target' is not a directory."
echo "$msg"
log_action "$msg"
exit 1
fi

echo "Listing files in '$target':"
ls -la "$target"
log_action "Listed directory: '$target'"
;;

rename)
old_name="$2"
new_name="$3"

if [[ -z "$old_name" || -z "$new_name" ]]; then
echo "Error: Please provide source and destination names."
usage
exit 1
fi

if [[ ! -e "$old_name" ]]; then
msg="Rename failed: '$old_name' does not exist."
echo "$msg"
log_action "$msg"
exit 1
fi

if [[ -e "$new_name" ]]; then
msg="Rename failed: '$new_name' already exists."
echo "$msg"
log_action "$msg"
exit 1
fi

mv "$old_name" "$new_name"
msg="Renamed '$old_name' to '$new_name'"
echo "$msg"
log_action "$msg"
;;

*)
echo "Error: Invalid command."
usage
exit 1
;;
esac
4 changes: 4 additions & 0 deletions scripts/logs/user_info.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Name: Israel | Age: 27 | Country: Nigeria | Category: Adult



35 changes: 35 additions & 0 deletions scripts/process_monitor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

LOG_DIR="logs"
LOG_FILE="$LOG_DIR/process_monitor.log"
services=("nginx" "ssh" "docker")

mkdir -p "$LOG_DIR"

timestamp() {
date "+%Y-%m-%d %H:%M:%S"
}

log_action() {
echo "[$(timestamp)] $1" | tee -a "$LOG_FILE"
}

process_name="$1"

if [[ -z "$process_name" ]]; then
echo "Usage: $0 <process_name>"
echo "Supported examples: ${services[*]}"
exit 1
fi

if pgrep -x "$process_name" >/dev/null 2>&1 || pgrep -f "$process_name" >/dev/null 2>&1; then
log_action "Process '$process_name' status: Running"
exit 0
fi

log_action "Process '$process_name' status: Stopped"

# Simulate restart for safety in student environments.
log_action "Attempting restart for '$process_name' (simulated)..."
sleep 1
log_action "Process '$process_name' status: Restarted (simulated)"
15 changes: 15 additions & 0 deletions scripts/system_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

echo "Enter your name:"
read name

echo "Enter your age:"
read age

echo "Enter your country:"
read country

if [ -z "$name" ] || [ -z "$age" ] || [ -z "$country" ]; then
echo "Error: All fields are required."
exit 1
fi
Loading