79 lines
2.3 KiB
Plaintext
79 lines
2.3 KiB
Plaintext
#!/usr/bin/env luash
|
|
-- System Administration Demo: Real-world sysadmin tasks
|
|
|
|
print("=== System Administration with Luash ===\n")
|
|
|
|
-- System information gathering
|
|
print("1. System Information:")
|
|
os_name = `uname -s`
|
|
architecture = `uname -m`
|
|
uptime_info = `uptime`
|
|
|
|
print(" OS: " .. os_name)
|
|
print(" Architecture: " .. architecture)
|
|
print(" Uptime: " .. uptime_info)
|
|
|
|
-- Process management
|
|
print("\n2. Process Management:")
|
|
process_count = `ps aux | wc -l`
|
|
print(" Total processes: " .. process_count)
|
|
|
|
-- Check if important services are running
|
|
print("\n3. Service Status Check:")
|
|
services = {"ssh", "cron", "systemd"}
|
|
for i = 1, #services do
|
|
local service = services[i]
|
|
local result = `pgrep #{service} | wc -l`
|
|
if tonumber(result) > 0 then
|
|
print(" ✓ " .. service .. " is running")
|
|
else
|
|
print(" ✗ " .. service .. " not found")
|
|
end
|
|
end
|
|
|
|
-- Disk usage analysis
|
|
print("\n4. Disk Usage:")
|
|
disk_usage = `df -h /`
|
|
print(" Root filesystem:")
|
|
!df -h / | tail -1
|
|
|
|
-- Log file analysis
|
|
print("\n5. Log Analysis:")
|
|
if `test -f /var/log/syslog && echo "exists"` == "exists" then
|
|
print(" Recent system errors:")
|
|
!tail -5 /var/log/syslog | grep -i error || echo " No recent errors found"
|
|
else
|
|
print(" Syslog not accessible (normal on macOS)")
|
|
end
|
|
|
|
-- Network connectivity check
|
|
print("\n6. Network Check:")
|
|
hosts_to_check = {"google.com", "github.com"}
|
|
for i = 1, #hosts_to_check do
|
|
local host = hosts_to_check[i]
|
|
local ping_result = `ping -c 1 #{host} >/dev/null 2>&1 && echo "ok" || echo "fail"`
|
|
if ping_result == "ok" then
|
|
print(" ✓ " .. host .. " is reachable")
|
|
else
|
|
print(" ✗ " .. host .. " is unreachable")
|
|
end
|
|
end
|
|
|
|
-- Generate a simple system report
|
|
print("\n7. Generating System Report:")
|
|
$REPORT_DATE = `date`
|
|
report = "System Report - " .. $REPORT_DATE .. "\n"
|
|
report = report .. "User: " .. $USER .. "\n"
|
|
report = report .. "System: " .. os_name .. " " .. architecture .. "\n"
|
|
report = report .. "Processes: " .. process_count .. "\n"
|
|
|
|
-- Write report to file (using Lua's file operations)
|
|
local file = io.open("system_report.txt", "w")
|
|
if file then
|
|
file:write(report)
|
|
file:close()
|
|
print(" Report saved to system_report.txt")
|
|
else
|
|
print(" Failed to write report file")
|
|
end
|