

Show HN: New unix utility "when" - apgwoz
https://github.com/apgwoz/when

======
apgwoz
I've so far only tested this on OS X, and have mostly used it with the `-t`
mode to have it notify me (via "say") when ssh succeeds on a CloudFormation
spawned AWS instance.

------
laumars
This could be quite handy as need to do this sort of thing surprisingly often
and usually resort to a shell script one-liner like this:

    
    
        while true; do echo "hello world"; sleep 3; done
    

While that above code is pretty trivial to type, having a utility to this
would be a great time saver for the lazy sysadmin :)

edit: someone else just posted about _watch_ [1], never knew that existed
before today. You learn something new every day :D

[1]
[https://news.ycombinator.com/item?id=6888640](https://news.ycombinator.com/item?id=6888640)

------
lipanski
What's the difference between this and the bash '&&' operator? Except for the
timebomb flag, I don't really see any difference. Please correct me if I got
this wrong.

The '&&' operator, as in _which ruby && echo 'found it!'_, triggers the second
command, if the exit code of the first one is 0.

Also good to note, the '||' operator triggers the second command only if the
exit code of the first one is different than 0. As in _which ruby123456 ||
echo 'could not find it!'_.

EDIT: typo.

~~~
bichiliad
It looks like if the first parameter fails, then it is re-run until it
succeeds.

------
chingjun
What is the difference between this and 'while true; do cmd1 && cmd2; sleep 1;
done'

~~~
mooism2
It looks to me more like

    
    
      until cmd1 ; do sleep 1 ; done ; cmd2

~~~
apgwoz
Exactly. But, see the -t flag, which is the real reason I wrote it. -t is a
non-trivial script (if it's even possible in shell).

It defaults to the until behavior because it's most common.

~~~
sciurus
Could you give some more examples of how you use `-t` ?

------
apetresc
I went to go add a Homebrew formula for the name 'when', but it seems to be
taken by this command-line calendar app:
[http://www.lightandmatter.com/when/when.html](http://www.lightandmatter.com/when/when.html)

~~~
apgwoz
I struggled with a name. This morning in the shower, I liked "trip" but, I'm
not sure I'll change it--certainly not because of homebrew.

------
mphillips34
watch -n 1 foo && echo "why does this exist?"

~~~
apgwoz
Yes. See the -t flag. That's the reason I wrote it.

