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

LOG_FILE="logs/app.log"

while true; do
echo "1. Run all"
echo "2. System check"
echo "3. Backup"
echo "4. Exit"

read -p "Choose option: " choice

case $choice in
1)
./scripts/user_info.sh
./scripts/system_check.sh
echo "Ran all scripts" >> $LOG_FILE
;;
2)
./scripts/system_check.sh
;;
3)
read -p "Enter directory to backup: " dir
./scripts/backup.sh $dir
;;
4)
exit 0
;;
*)
echo "Invalid choice"
;;
esac
done
23 changes: 23 additions & 0 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

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

mkdir -p $BACKUP_DIR

dir=$1

if [ ! -d "$dir" ]; then
echo "Directory does not exist!" | 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 $dir

echo "Backup created: $backup_file" | tee -a $LOG_FILE

# Keep only last 5 backups
ls -t $BACKUP_DIR | tail -n +6 | xargs -I {} rm -- "$BACKUP_DIR/{}"
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="../logs/file_manager.log"

action=$1
file=$2
new_name=$3

case $action in
create)
if [ -f "$file" ]; then
echo "File already exists!" | tee -a $LOG_FILE
else
touch "$file"
echo "Created $file" | tee -a $LOG_FILE
fi
;;

delete)
if [ -f "$file" ]; then
rm "$file"
echo "Deleted $file" | tee -a $LOG_FILE
else
echo " File not found!" | tee -a $LOG_FILE
fi
;;

list)
ls -l | tee -a $LOG_FILE
;;

rename)
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 "Invalid command" | tee -a $LOG_FILE
;;
esac
14 changes: 14 additions & 0 deletions scripts/process_monitor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

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

process=$1

if pgrep $process > /dev/null
then
echo "$process is Running" | tee -a LOG_FILE
else
echo "$process is stopped. Restarting..." | tee -a $LOG_FILE
echo "$process Restarted (simulated)" | tee -a $LOG_FILE
fi
Empty file added scripts/sdystem_check.sh
Empty file.
27 changes: 27 additions & 0 deletions scripts/system_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

DATE=$(date +%Y-%M-%d)
LOG_FILE="../logs/system_report_$DATE.log"

echo "System Report - $DATE" | tee $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 warning
df -h | awk '$5 > 80 {print "Warning; High disk usage on " $6}' | tee -a $LOG_FILE

# Process count
echo "Total Processes:" | tee -a $LOG_FILE
ps aux | wc -1 | tee -a $LOG_FILE

# Top 5 memory processes
echo "Top 5 Memory Consuming Processes:" | tee -a $LOG_FILE
ps aux --sort=-%mem | head -n 6 | tee -a $LOG_FILE

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

LOG_FILE="../logs/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
f1

if ! [[ "$age" =~ ^[0-9]+$ ]]; then
echo "Error: Age must be a number." | tee -a $LOG_FILE
exit 1
f1

# Age category
if [ "$age" -1t 18 ]; then
category="Minor"
elif [ "$age" -1e 65 ]; then
category="Adult"
else
category="Senior"
fi

message="Hello $name from $country. You are an $category."

echo $message | tee -a $LOG_FILE