Git Product home page Git Product logo

Comments (2)

rfmoz avatar rfmoz commented on September 6, 2024

Hello Martin,

Thanks for present your case, it's always interesting to know the different ways of using Tuptime.

The requirement proposed falls into a type of filtering that could be called "advance filtering", because it is possible to normalize it to the point of reaching a register ID or a timestamp, any of them already covered by existing arguments, like --until, --since, --at, --exclude, --tsince, --tuntil, --tat.

Please, let me summarize, plus yours, a few other examples that I've know:

  • --since-non-graceful - Since the startup following the most recent non-graceful shutdown.
  • --skip-bad-shutdown - All startups with a clean shutdown.
  • --only-bad-shutdown - All startups with a bad shutdown.
  • --last-bad-shutdown - Indentify only the last register when the system had a non-graceul shutdown.

And also with time:

  • --since-last [month|week|day] - Report usual time ranges.

In some environments, like yours, they offer the key to use Tuptime, but they are like shortcuts. Tuptime offers strong and reliable primitives to construct basic filtering, allowing users to narrow down the range in any way they imagine.

If it offers one of these options, why not other that could be essential in other environment? At the end, the proyect would move away the good design trends, like Unix Philosophy and Suckless Philosophy

Anyway, to offer an alternative, if you put this little script in a folder listed in your $PATH before "/usr/bin", for example "/usr/local/bin" you'll have the expected behaviour.

#!/bin/bash

EXE='/usr/bin/tuptime'

# Process new argument if it exists
if [[ "$1" == "--since-non-graceful" ]]; then

        # Remove it from argument list
        set -- "${@/--since-non-graceful/}"

        # Set argument value:
        #  - Order table by 'e'nd status
        #  - Grep last BAD register
        #  - Increase in 1 their No.
        VAL1=`$EXE --table --order e | grep BAD | tail -1 | awk '{print $1 + 1}'`

        # Set new behaviour
        if [ -n "$VAL1" ]; then
                set -- "$@" "--since" "$VAL1"
        fi
fi

# Call with arguments 
$EXE $@

Also, I slighly improve your filter using --order e to avoid one pipe step.

Now, executing it with the new argument will produce the expected result:

$ tuptime --since-non-graceful

from tuptime.

mschmitt avatar mschmitt commented on September 6, 2024

Thanks for your feedback!

My request is totally not in the --last-year class, because this seems to be flawlessly covered by --tsince and --tuntil, but now that you outlined a few additional use cases, --since-previous-graceful-until-previous-non-graceful would be something I could see myself also being interested in. ;-)

I'll test a shell function that does the filtering. :-)

function tuptime-graceful () {
        local tuptime_since=1
        local temp_array
        while read -r line 
        do
                if [[ "${line}" =~ ' BAD ' ]]
                then
                        read -r -a temp_array <<< "${line}"
                        tuptime_since=$(( temp_array[0] + 1 ))
                        break
                fi
        done < <(tuptime --table --order e --reverse)
        tuptime --since "${tuptime_since}"
}

from tuptime.

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.