Giter Site home page Giter Site logo

Comments (7)

wick3dr0se avatar wick3dr0se commented on May 27, 2024

Upon merge of PR #20 this issue is fixed

from sysfetch.

nathhad avatar nathhad commented on May 27, 2024

Confirmed fixed by pull request #20 and working (tested in place). Thanks!

from sysfetch.

wick3dr0se avatar wick3dr0se commented on May 27, 2024

commit 9eeaba1 changes if statement to read for uptime --pretty command instead. Thank you for the great work!

from sysfetch.

nathhad avatar nathhad commented on May 27, 2024

commit 9eeeaba1 reverted the fix - command -v uptime --pretty does not successfully verify support for --pretty on busybox. So far the only thing I've found that clearly works is testing whether calling the command in question symlinks back to /bin/busybox.

from sysfetch.

wick3dr0se avatar wick3dr0se commented on May 27, 2024

I reopened the issue. Hoping we can find a way to print 'uptime' on busybox without path refrence to os

from sysfetch.

nathhad avatar nathhad commented on May 27, 2024

Got it. One option, since there seem to have been other small systems that don't have the full version of uptime --pretty would be to just pull the raw uptime value (first field in /proc/uptime) and reformat it ourselves. That method is guaranteed to work the same on every Linux based system I've ever seen myself, and it's actually easier to process that value (which is just uptime in raw seconds) than trying to strip it out of the output of any of the uptime commands. Should only take a dozen lines of code, I don't have fetch handy to work directly but here is a code snippet you can use to extract, then format however you'd like:

#!/bin/bash
# Get raw seconds value
RAWSEC=$(cat /proc/uptime | awk '{print $1}')
# Cut off decimal
RAWSEC=${RAWSEC%\.*}
echo $RAWSEC
# Extract weeks
WEEKS=$((RAWSEC/604800))
REMSEC=$((RAWSEC%604800))
echo "$WEEKS weeks and $REMSEC seconds"
# Extract days
DAYS=$((REMSEC/86400))
REMSEC=$((REMSEC%86400))
echo "$WEEKS weeks, $DAYS days and $REMSEC seconds"
# Extract hours
HOURS=$((REMSEC/3600))
REMSEC=$((REMSEC%3600))
echo "$WEEKS weeks, $DAYS days, $HOURS hours and $REMSEC seconds"
# Extract minutes
MINUTES=$((REMSEC/60))
REMSEC=$((REMSEC%60))
echo "$WEEKS weeks, $DAYS days, $HOURS hours, $MINUTES min and $REMSEC seconds"
# format it however you like
echo "Compare to output of uptime --pretty:"
uptime --pretty

That produces the following terminal output:

chuck@vapor:~/code$ ./uptime.sh
5972231
9 weeks and 529031 seconds
9 weeks, 6 days and 10631 seconds
9 weeks, 6 days, 2 hours and 3431 seconds
9 weeks, 6 days, 2 hours, 57 min and 11 seconds
Compare to output of uptime --pretty:
up 9 weeks, 6 days, 2 hours, 57 minutes

Once you strip out my comments, you can use that to extract a time pattern that works on any system, even the tiny ones like Alpine and OpenWRT, no doubts.

from sysfetch.

wick3dr0se avatar wick3dr0se commented on May 27, 2024

Check out commit de093b4

from sysfetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.