-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem-maintenance.sh
95 lines (83 loc) · 1.95 KB
/
system-maintenance.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# System Updates
function update_system() {
sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y
sudo apt autoclean
}
# Disk Space Management
function check_disk_space() {
echo "Disk Space Usage:"
df -h /
# Alert if disk usage is over 90%
use=$(df -h / | awk 'NR==2 {print $5}' | sed 's/%//')
if [ "$use" -gt 90 ]; then
echo "WARNING: Disk usage is over 90%"
fi
}
# Cache Cleanup
function clean_cache() {
sudo rm -rf /var/cache/apt/archives/*.deb
sudo rm -rf ~/.cache/thumbnails/*
}
# System Health Check
function check_system_health() {
echo "Memory Usage:"
free -h
echo "CPU Load:"
uptime
echo "System Temperature:"
if command -v sensors &> /dev/null; then
sensors
else
echo "sensors command not found. Installing..."
sudo apt install -y lm-sensors
sensors
fi
}
# Docker Cleanup (if installed)
function clean_docker() {
if command -v docker &> /dev/null; then
echo "Cleaning unused Docker resources..."
docker system prune -af --volumes
fi
}
# Log Rotation
function rotate_logs() {
sudo journalctl --vacuum-time=7d
}
# Main menu
while true; do
echo "
System Maintenance Menu:
1. Run System Updates
2. Check Disk Space
3. Clean System Cache
4. Check System Health
5. Clean Docker (if installed)
6. Rotate System Logs
7. Run All Maintenance Tasks
8. Exit
"
read -p "Select an option (1-8): " choice
case $choice in
1) update_system ;;
2) check_disk_space ;;
3) clean_cache ;;
4) check_system_health ;;
5) clean_docker ;;
6) rotate_logs ;;
7)
update_system
check_disk_space
clean_cache
check_system_health
clean_docker
rotate_logs
;;
8) exit 0 ;;
*) echo "Invalid option" ;;
esac
read -p "Press enter to continue..."
done