Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/env bash
  2. # tivasyk <[email protected]>
  3.  
  4. # Alternative (the right) way to get uptime
  5. DUMP_STRING=$(cat /proc/uptime)
  6. printf "Raw data: %s\n" "${DUMP_STRING}"
  7.   TOTAL_SECS=${DUMP_STRING%%.*}
  8. printf "Seconds:  %s\n" "${TOTAL_SECS}"
  9.  
  10. DAYS=$(( TOTAL_SECS / 86400 ))
  11. HOURS=$(( (TOTAL_SECS - DAYS*86400) / 3600 ))
  12. MINUTES=$(( (TOTAL_SECS - DAYS*86400 - HOURS*3600) / 60 ))
  13. SECONDS=$(( TOTAL_SECS - DAYS*86400 - HOURS*3600 - MINUTES*60 ))
  14.  
  15. HOURS="0${HOURS}"; HOURS="${HOURS:(-2)}"
  16. MINUTES="0${MINUTES}"; MINUTES="${MINUTES:(-2)}"
  17. SECONDS="0${SECONDS}"; SECONDS="${SECONDS:(-2)}"
  18.  
  19. printf "Uptime: ${DAYS} days, ${HOURS}:${MINUTES}:${SECONDS}\n"