1. 33

  2. 6

    The timeout utility is very handy, but I frequently find it lacking. I used expect to make a very simple version, which extends the timeout each time there is output:

    #!/usr/bin/expect -f
    if {$argc < 2} {
        send_user "$argv0 timeout script\n"
        send_user "\n"
        send_user "Example: $argv0 5 fetchmail.sh\n"
        exit 1
    set timeout [lindex $argv 0]
    exit -onexit {
        catch {close}
    spawn {*}[lrange $argv 1 end]
    expect {
        -re ".+" {
        timeout {
            send_user "\n<timeout>\n"
        eof {
            send_user "\n<eof>\n"
    1. 2

      I think this is the first use of expect I’ve ever seen outside testing–and the first usage regardless in a number of years.

      1. 4

        I know, expect has really fallen out of favor. Unfortunate, too, as it is an extraordinary and powerful tool. I have a similar expect script which automates puppet noop testing by managing multiple interactive SSH sessions and the various commands needed to noop a new change in git. Fairly simple, and has saved me hours of tedium.

    2. 2

      No mention of seq? Poser!

      Another nice one is fmt.

      1. 3

        You mean jot which has a name I’ll never understand

        1. 2

          BSD zealot detected.

          (Actually I learned about the concept from jot and it still has a better syntax I think).

          1. 1

            Not a zealot, just seq is never on any server I use at work or home. Or on OSX.

            It also has features I never knew about nor would I associate with the tool.

            edit: wait seq is on OSX now? I swear it wasn’t

            1. 2

              “BSD zealot” is actually a compliment ;)

        2. 3

          par is the better fmt. It only uses one space between sentences.

          1. 2

            Sec in zsh is as easy as, e.g. {4..7}.

          2. 2

            Since we’re all about to toss our favorites in, I might as well get mine in:

            watch -d -n5 'cat foo' beats the hell out of cat foo (wait an indeterminate amount of time), up arrow, enter, repeat.

            brew install on OS X!

            1. 1

              One I stumbled upon recently was leave which lets you specify a time you need to leave, and will then alert you on your tty that it’s time to leave. Also… yes though, I don’t really use it often.

              1. 1

                pee, other than being amusingly named, let us…ahem…‘lol scale’ by being able to shard a pipeline at $ORK[-1].

                To do the job properly I would have needed to hack at some cpython and C code, but we needed a faster fix so I used pee, piped into awk (to modulo hash and filter) and then into multiple spawned copies of the next stage of the processing pipeline, which was single threaded.

                We bought ourselves a 2x speedup for a week by effectively processing 300% of our data, till I found the time and motivation to do the job properly.

                …and that’s why I drink</Doug Stanhope>

                1. 1

                  xargs -P is life.

                  1. 3

                    I’ve switched over to using parallel in place of xargs. It doesn’t come with the system and it’s a big ball of perl, but sweet jesus it is powerful.

                    1. 1

                      Hah, indeed!

                      Better still when you use it to replace 5k+ multi-threaded C++ LoC much to the dismay of the developers.