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_20260331_191330.tar.gz
Binary file not shown.
Binary file added backups/backup_20260331_194052.tar.gz
Binary file not shown.
Binary file added backups/backup_20260331_201324.tar.gz
Binary file not shown.
Binary file added backups/backup_20260331_212620.tar.gz
Binary file not shown.
Binary file added backups/backup_20260331_213028.tar.gz
Binary file not shown.
2 changes: 2 additions & 0 deletions file_manager.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# jonas dairy

62 changes: 62 additions & 0 deletions log/app.log
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions log/backup.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Error: Directory does not exist
Usage: backup.sh <Source directory>
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
20 changes: 20 additions & 0 deletions log/file_manager.log
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions log/process_monitor.log
Original file line number Diff line number Diff line change
@@ -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
66 changes: 66 additions & 0 deletions log/system_report_2026.log
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions log/user_info.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hello Joseph from 9ja! You are an Adult.
Hello Joseph from 9ja! You are an Adult.
Binary file added scripts/.user_info.sh.swn
Binary file not shown.
Binary file added scripts/.user_info.sh.swo
Binary file not shown.
Binary file added scripts/.user_info.sh.swp
Binary file not shown.
26 changes: 26 additions & 0 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
@@ -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 <Source directory>" | 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"

44 changes: 44 additions & 0 deletions scripts/file_manager.sh
Original file line number Diff line number Diff line change
@@ -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

17 changes: 17 additions & 0 deletions scripts/process_monitor.sh
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions scripts/run_all.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions scripts/simple1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash


30 changes: 30 additions & 0 deletions scripts/system_check.sh
Original file line number Diff line number Diff line change
@@ -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"


32 changes: 32 additions & 0 deletions scripts/user_info.sh
Original file line number Diff line number Diff line change
@@ -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"