-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.sh
More file actions
executable file
·163 lines (140 loc) · 4.71 KB
/
examples.sh
File metadata and controls
executable file
·163 lines (140 loc) · 4.71 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
################################################################################
# Examples Script for Shell Scripting Automation Toolkit
# Description: Demonstrates all major features of the toolkit
################################################################################
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TOOLKIT="${SCRIPT_DIR}/automation-toolkit.sh"
MONITOR="${SCRIPT_DIR}/health-monitor.sh"
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo ""
echo "=============================================================================="
echo " Shell Scripting Automation Toolkit - Interactive Examples"
echo "=============================================================================="
echo ""
# Function to pause between examples
pause() {
echo ""
read -p "Press Enter to continue to next example..." -r
echo ""
}
# Function to run example
run_example() {
local title="$1"
local description="$2"
local command="$3"
echo -e "${BLUE}=============================================================================="
echo -e "Example: $title"
echo -e "==============================================================================${NC}"
echo -e "${YELLOW}$description${NC}"
echo ""
echo -e "${GREEN}Command: $command${NC}"
echo ""
eval "$command"
echo ""
}
# Create test directory for demonstrations
TEST_DIR="/tmp/toolkit-demo-$$"
mkdir -p "$TEST_DIR"
echo "Test data for automation toolkit" > "$TEST_DIR/sample.txt"
echo "More test data" > "$TEST_DIR/data.txt"
echo "Test directory created at: $TEST_DIR"
echo ""
pause
# Example 1: Display Help
run_example \
"Display Help Menu" \
"Shows all available options and usage information" \
"$TOOLKIT --help"
pause
# Example 2: Create Backup
run_example \
"Create Backup" \
"Creates a compressed backup of the test directory" \
"$TOOLKIT --backup $TEST_DIR --verbose"
pause
# Example 3: List Backups
run_example \
"List Available Backups" \
"Shows all backups in the backup directory" \
"$TOOLKIT --list-backups"
pause
# Example 4: System Health Report
run_example \
"Generate System Health Report" \
"Creates a comprehensive health report with CPU, memory, and disk metrics" \
"$TOOLKIT --health --verbose"
pause
# Example 5: Comprehensive Health Check
run_example \
"Comprehensive Health Check with Alerts" \
"Runs a full system health check and shows any alerts" \
"$TOOLKIT --all-health"
pause
# Example 6: Disk Usage
run_example \
"Check Disk Usage" \
"Analyzes disk usage for the test directory" \
"$TOOLKIT --disk-usage $TEST_DIR"
pause
# Example 7: Compress Directory
run_example \
"Compress Directory" \
"Creates a compressed archive of the test directory" \
"$TOOLKIT --compress $TEST_DIR"
pause
# Example 8: Health Monitor - Single Check
run_example \
"Health Monitor - Single Check" \
"Runs a one-time health check of system services" \
"$MONITOR --check --verbose"
pause
# Example 9: Health Monitor - Service Specific
run_example \
"Monitor Specific Services" \
"Checks the status of SSH and Cron services" \
"$MONITOR --service ssh --service cron --check --verbose"
pause
# Example 10: View Alerts
run_example \
"View Recent Alerts" \
"Displays the most recent system alerts (if any)" \
"$MONITOR --list-alerts"
pause
# Cleanup
echo -e "${BLUE}=============================================================================="
echo -e " Cleanup"
echo -e "==============================================================================${NC}"
echo ""
echo "Cleaning up test directory and files..."
rm -rf "$TEST_DIR"
rm -f "${TEST_DIR}.tar.gz"
echo "Cleanup complete!"
echo ""
echo -e "${GREEN}=============================================================================="
echo -e " Examples Demonstration Complete!"
echo -e "==============================================================================${NC}"
echo ""
echo "You have now seen all major features of the toolkit:"
echo ""
echo " ✓ File backups and compression"
echo " ✓ System health monitoring"
echo " ✓ Service monitoring and alerts"
echo " ✓ Disk usage analysis"
echo " ✓ Comprehensive health reporting"
echo ""
echo "To use these features in your workflow:"
echo " 1. Read the README.md for detailed documentation"
echo " 2. Customize config/config.conf for your needs"
echo " 3. Schedule tasks with cron for automation"
echo ""
echo "For help at any time, use:"
echo " ./automation-toolkit.sh --help"
echo " ./health-monitor.sh --help"
echo ""
echo "=============================================================================="
echo ""