Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # tivasyk <tivasyk@gmail.com>
- # Alternative (the right) way to get uptime
- DUMP_STRING=$(cat /proc/uptime)
- printf "Raw data: %s\n" "${DUMP_STRING}"
- TOTAL_SECS=${DUMP_STRING%%.*}
- printf "Seconds: %s\n" "${TOTAL_SECS}"
- DAYS=$(( TOTAL_SECS / 86400 ))
- HOURS=$(( (TOTAL_SECS - DAYS*86400) / 3600 ))
- MINUTES=$(( (TOTAL_SECS - DAYS*86400 - HOURS*3600) / 60 ))
- SECONDS=$(( TOTAL_SECS - DAYS*86400 - HOURS*3600 - MINUTES*60 ))
- HOURS="0${HOURS}"; HOURS="${HOURS:(-2)}"
- MINUTES="0${MINUTES}"; MINUTES="${MINUTES:(-2)}"
- SECONDS="0${SECONDS}"; SECONDS="${SECONDS:(-2)}"
- printf "Uptime: ${DAYS} days, ${HOURS}:${MINUTES}:${SECONDS}\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement