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
55 changes: 55 additions & 0 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
set -euo pipefail

# -------------------------
# Variables
# -------------------------
BACKUP_DIR="backups"
LOG_FILE="backup.log"
TIMESTAMP=$(date +%F_%H-%M-%S)

# -------------------------
# Check input
# -------------------------
if [ $# -ne 1 ]; then
echo "Usage: $0 <directory>"
exit 1
fi

SOURCE_DIR="$1"

# -------------------------
# Validate directory
# -------------------------
if [ ! -d "$SOURCE_DIR" ]; then
echo "Error: Directory does not exist!"
exit 1
fi

# -------------------------
# Create backup directory
# -------------------------
mkdir -p "$BACKUP_DIR"

# -------------------------
# Create backup
# -------------------------
BACKUP_FILE="$BACKUP_DIR/backup_$TIMESTAMP.tar.gz"

tar -czf "$BACKUP_FILE" "$SOURCE_DIR"

echo "$(date) - Backup created: $BACKUP_FILE" >> "$LOG_FILE"

# -------------------------
# Keep only last 5 backups
# -------------------------
cd "$BACKUP_DIR"

ls -t backup_*.tar.gz 2>/dev/null | tail -n +6 | while read -r old_backup; do
rm -f "$old_backup"
echo "$(date) - Deleted old backup: $old_backup" >> "../$LOG_FILE"
done

cd - >/dev/null

echo "Backup completed successfully!"
Binary file added scripts/backups/backup_2026-04-03_17-02-19.tar.gz
Binary file not shown.
Empty file added scripts/file1.txt
Empty file.
Empty file added scripts/file_1.txt
Empty file.
86 changes: 86 additions & 0 deletions scripts/file_manager.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

LOG_FILE="logs/file_manager.log"

# Ensure logs directory exists
mkdir -p logs

# Function to log actions
log_action() {
local message="$1"
echo "$(date) - $message" >> "$LOG_FILE"
}

# Check for at least 2 arguments
if [ $# -lt 2 ]; then
echo "Usage: $0 {create|delete|list|rename} <filename> [newname]"
exit 1
fi

COMMAND=$1
FILE=$2

case $COMMAND in
create)
# Auto-rename if file exists
base="$FILE"
ext=""
if [[ "$FILE" == *.* ]]; then
base="${FILE%.*}"
ext=".${FILE##*.}"
fi

counter=1
newfile="$FILE"
while [ -e "$newfile" ]; do
newfile="${base}_$counter$ext"
((counter++))
done

touch "$newfile"
echo "File created: $newfile"
log_action "CREATE: $newfile"
;;

delete)
if [ ! -e "$FILE" ]; then
echo "Error: $FILE does not exist."
log_action "DELETE FAILED: $FILE does not exist"
else
rm -i "$FILE"
echo "File deleted: $FILE"
log_action "DELETE: $FILE"
fi
;;

list)
echo "Files in current directory:"
ls -lah
log_action "LIST directory"
;;

rename)
NEW_NAME=$3
if [ -z "$NEW_NAME" ]; then
echo "Error: You must provide a new name for the file."
exit 1
fi
if [ ! -e "$FILE" ]; then
echo "Error: $FILE does not exist."
log_action "RENAME FAILED: $FILE does not exist"
elif [ -e "$NEW_NAME" ]; then
echo "Error: $NEW_NAME already exists. Aborting."
log_action "RENAME FAILED: $NEW_NAME already exists"
else
mv "$FILE" "$NEW_NAME"
echo "File renamed from $FILE to $NEW_NAME"
log_action "RENAME: $FILE -> $NEW_NAME"
fi
;;

*)
echo "Unknown command: $COMMAND"
echo "Usage: $0 {create|delete|list|rename} <filename> [newname]"
exit 1
;;
esac
Empty file added scripts/filenew.txt
Empty file.
Empty file added scripts/fille.txt
Empty file.
25 changes: 25 additions & 0 deletions scripts/fille_manager.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

echo "Before creating folder_1 and file_1"
ls

# to create a directory and file
mkdir folder_1
touch file_1

echo "After creating folder_1 and file_1"
ls

# to rename directory and file
mv folder_1 tsfolder
mv file_1 tsfile

echo "After renaming folder_1 and file_1"
ls


#deleting dir and file
rm -rf tsfolder
rm -f tsfile
echo "After removing tsfolder and tsfile"
ls
11 changes: 11 additions & 0 deletions scripts/logs/app.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
2026-04-03 18:39:03 - Running all scripts...
2026-04-03 18:39:03 - Running system check...
2026-04-03 18:39:03 - process_monitor.sh not found or not executable
2026-04-03 18:39:03 - Running backup...
2026-04-03 18:39:14 - backup.sh not found or not executable
2026-04-03 18:39:14 - All tasks completed
2026-04-03 18:39:18 - Running system check...
2026-04-03 18:39:18 - process_monitor.sh not found or not executable
2026-04-03 18:39:32 - Running backup...
2026-04-03 18:39:39 - backup.sh not found or not executable
2026-04-03 18:39:44 - Exiting application
8 changes: 8 additions & 0 deletions scripts/logs/file_manager.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Mon Mar 30 21:58:24 WAT 2026 - CREATE: file_1.txt
Mon Mar 30 21:59:26 WAT 2026 - RENAME: file.txt -> filenew.txt
Mon Mar 30 22:00:08 WAT 2026 - DELETE FAILED: file.txt does not exist
Mon Mar 30 22:00:47 WAT 2026 - CREATE: file1.txt
Fri Apr 3 15:57:21 WAT 2026 - CREATE: file.txt
Fri Apr 3 15:58:37 WAT 2026 - RENAME: file.txt -> fille.txt
Fri Apr 3 16:32:20 WAT 2026 - CREATE: file_2.txt
Fri Apr 3 16:32:51 WAT 2026 - DELETE: file_2.txt
24 changes: 24 additions & 0 deletions scripts/logs/system_report_2026-03-30_22-26-54.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 476G 113G 364G 24% /usr/lib/wsl/drivers
/dev/sdd 1007G 1.4G 955G 1% /
none 1.9G 308K 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 516K 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:\ 476G 113G 364G 24% /mnt/c
tmpfs 378M 20K 378M 1% /run/user/1000

total used free shared buff/cache available
Mem: 3771 413 3166 3 268 3357
Swap: 1024 0 1024

22:26:54 up 5:38, 1 user, load average: 0.00, 0.00, 0.00

=== Disk Usage Warnings ===

41 changes: 41 additions & 0 deletions scripts/logs/system_report_2026-03-30_22-32-31.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
=== System Check Report ===
Date: Mon Mar 30 22:32:31 CEST 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 476G 113G 363G 24% /usr/lib/wsl/drivers
/dev/sdd 1007G 1.4G 955G 1% /
none 1.9G 308K 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 520K 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:\ 476G 113G 363G 24% /mnt/c
tmpfs 378M 20K 378M 1% /run/user/1000

=== Disk Usage Warnings (>80%) ===

=== Memory Usage (MB) ===
total used free shared buff/cache available
Mem: 3771 416 3162 3 269 3354
Swap: 1024 0 1024

=== CPU Load ===
22:32:31 up 5:44, 1 user, load average: 0.00, 0.00, 0.00

=== Total Running Processes ===
Total processes: 33

=== Top 5 Memory-Consuming Processes ===
PID PPID CMD %MEM %CPU
206 1 /usr/bin/python3 /usr/share 0.5 0.0
42 1 /usr/lib/systemd/systemd-jo 0.3 0.0
2281 1 /usr/libexec/wsl-pro-servic 0.3 0.1
1 0 /sbin/init 0.3 0.0
104 1 /usr/lib/systemd/systemd-re 0.3 0.0

41 changes: 41 additions & 0 deletions scripts/logs/system_report_2026-04-03_15-40-51.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
=== System Check Report ===
Date: Fri Apr 3 15:40:51 WAT 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 476G 114G 363G 24% /usr/lib/wsl/drivers
/dev/sdd 1007G 1.4G 955G 1% /
none 1.9G 372K 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 520K 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:\ 476G 114G 363G 24% /mnt/c
tmpfs 378M 20K 378M 1% /run/user/1000

=== Disk Usage Warnings (>80%) ===

=== Memory Usage (MB) ===
total used free shared buff/cache available
Mem: 3771 415 3233 3 199 3355
Swap: 1024 0 1024

=== CPU Load ===
15:40:51 up 7:30, 1 user, load average: 0.00, 0.00, 0.00

=== Total Running Processes ===
Total processes: 35

=== Top 5 Memory-Consuming Processes ===
PID PPID CMD %MEM %CPU
206 1 /usr/bin/python3 /usr/share 0.5 0.0
42 1 /usr/lib/systemd/systemd-jo 0.3 0.0
1 0 /sbin/init 0.3 0.0
104 1 /usr/lib/systemd/systemd-re 0.3 0.0
345 1 /usr/lib/systemd/systemd -- 0.2 0.0

5 changes: 5 additions & 0 deletions scripts/logs/user_info.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Mon Mar 30 20:49:55 WAT 2026 - Name: Daniel | Age: 45 | Country: Nigeria | Category: Adult
Fri Apr 3 15:23:12 WAT 2026 - Name: Daniel | Age: 3 | Country: Nigeria | Category: Minor
Fri Apr 3 15:24:46 WAT 2026 - Name: Aji | Age: 45 | Country: South Africa | Category: Adult
Fri Apr 3 15:27:05 WAT 2026 - Name: Aji | Age: 46 | Country: South Korea | Category: Adult
Fri Apr 3 15:31:09 WAT 2026 - Name: Aji | Age: 47 | Country: America | Category: Adult
44 changes: 44 additions & 0 deletions scripts/logs/user_info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

LOG_FILE="logs/user_info.log"

# Ensure logs directory exists
mkdir -p logs

echo "=== User Information Script ==="

# Prompt user for input
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."
echo "$(date) - ERROR: Missing input" >> "$LOG_FILE"
exit 1
fi

# Check if age is numeric
if ! [[ "$age" =~ ^[0-9]+$ ]]; then
echo "Error: Age must be a number."
echo "$(date) - ERROR: Invalid age input ($age)" >> "$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 message
message="Hello $name from $country! You are an $category."

echo "$message"

# Save to log file
echo "$(date) - Name: $name | Age: $age | Country: $country | Category: $category" >> "$LOG_FILE"
Loading