Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a app server that I start and it writes output to stdout. I want to be able to watch that output and issue a command (in this case growlnotify -m "Server is up") when a specific line is sent to stdout, but I still want the all the output go to stdout.

Note I'd rather not write to a file

share|improve this question
Note: I think (you should test this) on UNIX/Linux/MacOSX that if you decide at some point to kill the notifier app, since you're notified, you'd kill your server as well (unless you ignore SIGPIPE). So you'd need to keep it running or lose your server. – Rich Homolka Sep 10 '12 at 22:14
in the case of growl it's just sending an async message to a bg process that shows the notification on screen. You don't generally kill it but I have tested with the accepted answer and dismissing the message works fine without killing the server. – dstarh Sep 11 '12 at 2:41
up vote 2 down vote accepted

Pipe the output of the server command to a while loop:

server | while read; do if [[ $REPLY =~ "Server is up" ]]; then
    # do something
  echo "$REPLY"
share|improve this answer
You can have the server running in the background, writing to a log file. Then tail -f logfile | while read; do ...; done, using the same while loop as in the answer. – chepner Sep 10 '12 at 23:15
i always want the server in the foreground in this case so ctrl+c will stop it also don't want log files – dstarh Sep 11 '12 at 2:34
And we have a winner! this worked perfectly. – dstarh Sep 11 '12 at 2:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .