26 lines
957 B
Bash
Executable File
26 lines
957 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Check if the system is Linux or BSD
|
|
# if [[ "$(uname)" == "Linux" ]]; then
|
|
# # Get uptime in seconds for Linux
|
|
# total_uptime_seconds=$(cat /proc/uptime | awk '{print $1}')
|
|
if uname | grep -q "BSD"; then
|
|
# Get uptime in seconds for BSD
|
|
boot_time_seconds=$(sysctl -n kern.boottime | awk -F'[ ,]' '{print $4}')
|
|
total_uptime_seconds=$(($(date +%s) - boot_time_seconds))
|
|
else
|
|
total_uptime_seconds=$(cat /proc/uptime | awk '{print $1}')
|
|
# echo "UNKNOWN: Unsupported system"
|
|
# exit 3
|
|
fi
|
|
|
|
# Calculate uptime in days, hours, minutes, and seconds
|
|
uptime_days=$((total_uptime_seconds / 86400))
|
|
uptime_hours=$(( (total_uptime_seconds % 86400) / 3600 ))
|
|
uptime_minutes=$(( (total_uptime_seconds % 3600) / 60 ))
|
|
uptime_seconds=$((total_uptime_seconds % 60))
|
|
|
|
# Print the result and perfdata
|
|
echo "OK: Uptime is ${uptime_days}d ${uptime_hours}h ${uptime_minutes}m ${uptime_seconds}s | total_uptime_seconds=${total_uptime_seconds}s;"
|
|
exit 0
|