Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: New unix utility "when" (github.com/apgwoz)
20 points by apgwoz on Dec 11, 2013 | hide | past | favorite | 13 comments


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.


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


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.


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


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


It looks to me more like

  until cmd1 ; do sleep 1 ; done ; cmd2


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.


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


Yeah. I was thinking this.


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


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.


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


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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: