0% found this document useful (0 votes)
5 views

Linux Shell Scripts Project

The document contains a collection of Linux shell scripts for various system administration tasks. It includes scripts for gathering system information, monitoring disk usage, backing up files, updating packages, managing users, and cleaning log files. Each script is designed to automate specific functions to enhance system management efficiency.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Linux Shell Scripts Project

The document contains a collection of Linux shell scripts for various system administration tasks. It includes scripts for gathering system information, monitoring disk usage, backing up files, updating packages, managing users, and cleaning log files. Each script is designed to automate specific functions to enhance system management efficiency.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Linux Shell Scripts Project

1. System Info Script


#!/bin/bash

echo "System Information"


echo "------------------"
echo "Hostname: $(hostname)"
echo "Uptime: $(uptime -p)"
echo "Kernel Version: $(uname -r)"
echo "CPU Info: $(lscpu | grep 'Model name' | cut -d ':' -f2)"
echo "Memory Usage:"
free -h

2. Disk Usage Alert Script


#!/bin/bash

THRESHOLD=80
df -H | grep '^/dev/' | while read line; do
usage=$(echo $line | awk '{print $5}' | sed 's/%//')
partition=$(echo $line | awk '{print $1}')
if [ $usage -gt $THRESHOLD ]; then
echo "Warning: $partition is at ${usage}% usage"
fi
done

3. Backup Script
#!/bin/bash

SOURCE_DIR="/home/youruser/Documents"
BACKUP_DIR="/home/youruser/backups"
DATE=$(date +%F)

mkdir -p $BACKUP_DIR
tar -czf $BACKUP_DIR/backup-$DATE.tar.gz $SOURCE_DIR

echo "Backup completed for $SOURCE_DIR at $BACKUP_DIR/backup-$DATE.tar.gz"

4. Package Update Script


#!/bin/bash

echo "Updating package list..."


sudo apt update && sudo apt upgrade -y
echo "System update complete.

5. User Management Script


#!/bin/bash

echo "User Management"


echo "1. Add User"
echo "2. Delete User"
echo "3. List Users"
read -p "Choose an option [1-3]: " choice

case $choice in
1)
read -p "Enter username to add: " user
sudo adduser $user
;;
2)
read -p "Enter username to delete: " user
sudo deluser $user
;;
3)
cut -d: -f1 /etc/passwd
;;
*)
echo "Invalid option."
;;
esac

6. Log Cleaner Script


#!/bin/bash

LOG_DIR="/var/log"
DAYS=7

echo "Cleaning log files older than $DAYS days from $LOG_DIR"
sudo find $LOG_DIR -type f -mtime +$DAYS -exec rm -f {} \;
echo "Log cleanup complete.

You might also like