Uptime
how to calculate uptime in days or hours?
- get last reboot timestamp with
lastRebootTimestamp=$(sysctl kern.boottime | awk -F'[= |,]' '{print $6}')
- get now timestamp with
nowTimestamp=$(date +%s)
- calculate the difference
upTimestamp=$((nowTimestamp-lastRebootTimestamp))
- calculate days
uptimeDays=$((upTimestamp/(24*60*60)))
- calculate hours
uptimeHours=$((upTimestamp/(60*60)))