From e2a8f152a1f155c399202ac136c2f07a099468c3 Mon Sep 17 00:00:00 2001 From: Sayofunmi28 Date: Thu, 2 Apr 2026 15:31:25 +0100 Subject: [PATCH] feat: complete bash scripts --- System_check.sh | 47 +++++++++++++++++++++++++++++++++ _backup_20260401_153414.tar.gz | Bin 0 -> 115 bytes backup.sh | 28 ++++++++++++++++++++ bash-assignment | 1 + file_manager.sh | 7 +++++ logfile.log | 7 +++++ system_check_2026-03-30.log | 42 +++++++++++++++++++++++++++++ user_info.log | 0 user_info.sh | 37 ++++++++++++++++++++++++++ 9 files changed, 169 insertions(+) create mode 100755 System_check.sh create mode 100644 _backup_20260401_153414.tar.gz create mode 100755 backup.sh create mode 160000 bash-assignment create mode 100755 file_manager.sh create mode 100644 logfile.log create mode 100644 system_check_2026-03-30.log create mode 100644 user_info.log create mode 100755 user_info.sh diff --git a/System_check.sh b/System_check.sh new file mode 100755 index 0000000..94ee0a6 --- /dev/null +++ b/System_check.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# This script is for System Check Requirements + +log_file="system_check_$(date +%Y-%m-%d).log" + +# To start the log +{ +echo "===== SYSTEM CHECK REPORT =====" +echo "Date: $(date)" +echo "" + +# Disk usage +echo ">> Disk Usage:" +df -h +echo "" + +# Warning if disk usage exceeds 80% +echo ">> Disk Usage Warnings (Above 80%):" +df -h | awk 'NR>1 {gsub("%","",$5); if($5 > 80) print "WARNING: " $1 " is at " $5 "% usage"}' +echo "" + +# Memory usage +echo ">> Memory Usage (MB):" +free -m +echo "" + +# CPU load +echo ">> CPU Load:" +uptime +echo "" + +# Total running processes +echo ">> Total Running Processes:" +ps -e --no-headers | wc -l +echo "" + +# Top 5 memory-consuming processes +echo ">> Top 5 Memory-Consuming Processes:" +ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -n 6 +echo "" + +echo "===== END OF REPORT =====" + +} > "$log_file" + +echo "System check completed. Report saved to $log_file" diff --git a/_backup_20260401_153414.tar.gz b/_backup_20260401_153414.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..f6e7d92e12ae5f44ac4522bb9fb5a7f72f811aaa GIT binary patch literal 115 zcmb2|=3oE==C|hz`3@NfusGNswO1%B`M_y6kx6luOVOeK8-oG@97I>mO!L2``>tyC ztv@r~FE5$1aJS2wo3+pCrfWRkc&+17`O=IW3qEbRHTCAcw{>43W&_C& P?)vZE>u+PwU|;|M+#E7@ literal 0 HcmV?d00001 diff --git a/backup.sh b/backup.sh new file mode 100755 index 0000000..d62cabc --- /dev/null +++ b/backup.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# To make a directory + +dir="Learning" +if [[ -z "$dir" ]]; then + echo "$dir: is a directory" +fi + +# To check if a directory exists + +if [[ ! -d "$dir" ]]; then + echo "Yes, the directory exists." +fi + +# Creating timestamp + +TIMESTAMP=$(date +"%Y%m%d_%H%M%S") + +#Creating a Backup filename + +BACKUP_NAME="${dir}_backup_${TIMESTAMP}.tar.gz" + +echo "Backup: $BACKUP_NAME" + +tar -czf "$BACKUP" "$dir" + + diff --git a/bash-assignment b/bash-assignment new file mode 160000 index 0000000..bd24f9c --- /dev/null +++ b/bash-assignment @@ -0,0 +1 @@ +Subproject commit bd24f9c88ae29f8d2f637359b6ea9924919f3ae3 diff --git a/file_manager.sh b/file_manager.sh new file mode 100755 index 0000000..283563a --- /dev/null +++ b/file_manager.sh @@ -0,0 +1,7 @@ +#1/bin/bash + +# This script is to create file + +cat < file.txt +This is for text +EOF diff --git a/logfile.log b/logfile.log new file mode 100644 index 0000000..283563a --- /dev/null +++ b/logfile.log @@ -0,0 +1,7 @@ +#1/bin/bash + +# This script is to create file + +cat < file.txt +This is for text +EOF diff --git a/system_check_2026-03-30.log b/system_check_2026-03-30.log new file mode 100644 index 0000000..fc5d0d2 --- /dev/null +++ b/system_check_2026-03-30.log @@ -0,0 +1,42 @@ +===== SYSTEM CHECK REPORT ===== +Date: Mon Mar 30 14:14:49 WAT 2026 + +>> Disk Usage: +Filesystem Size Used Avail Use% Mounted on +none 2.9G 0 2.9G 0% /usr/lib/modules/6.6.87.2-microsoft-standard-WSL2 +none 2.9G 4.0K 2.9G 1% /mnt/wsl +drivers 699G 171G 528G 25% /usr/lib/wsl/drivers +/dev/sdd 1007G 1.6G 955G 1% / +none 2.9G 400K 2.9G 1% /mnt/wslg +none 2.9G 0 2.9G 0% /usr/lib/wsl/lib +rootfs 2.9G 2.7M 2.9G 1% /init +none 2.9G 488K 2.9G 1% /run +none 2.9G 0 2.9G 0% /run/lock +none 2.9G 0 2.9G 0% /run/shm +none 2.9G 76K 2.9G 1% /mnt/wslg/versions.txt +none 2.9G 76K 2.9G 1% /mnt/wslg/doc +C:\ 699G 171G 528G 25% /mnt/c +tmpfs 589M 8.0K 589M 1% /run/user/0 + +>> Disk Usage Warnings (Above 80%): + +>> Memory Usage (MB): + total used free shared buff/cache available +Mem: 5883 349 5335 3 198 5374 +Swap: 2048 0 2048 + +>> CPU Load: + 14:14:49 up 1 day, 22:45, 1 user, load average: 0.03, 0.02, 0.00 + +>> Total Running Processes: +41 + +>> Top 5 Memory-Consuming Processes: + PID PPID CMD %MEM %CPU + 14182 14083 /root/.vscode-remote-contai 0.9 0.0 + 308 1 /usr/bin/python3 /usr/share 0.3 0.0 + 707 1 /usr/libexec/packagekitd 0.3 0.0 + 216 1 /usr/bin/python3 /usr/bin/n 0.3 0.0 + 18872 1 /lib/systemd/systemd-resolv 0.2 0.0 + +===== END OF REPORT ===== diff --git a/user_info.log b/user_info.log new file mode 100644 index 0000000..e69de29 diff --git a/user_info.sh b/user_info.sh new file mode 100755 index 0000000..e1af72a --- /dev/null +++ b/user_info.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# This script is to collect user's data + +read -p "Enter your name: " name + +read -p "Enter your Age: " age + +read -p "Enter your Country: " country + +# Validating age to be numeric + +if ! [[ "$age" =~ ^[0-9]+$ ]]; then + echo "Age must be numeric." + exit 1 +fi + +# Greeting message for the user + +echo "Hello, $name you are $age years old, and you are from $country, welcome onboard." + +# categorising the user based on their ages + +if (( age < 18 )); then + category="Minor" + elif (( age <= 65 )); then + category="Adult" + else + category="Senior" +fi + +# Handle missing input + +if [[ -z "$name" || -z "$age" || -z "$country" ]]; then +echo "All fields (name, age, country) are required." + exit 1 +fi