Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
  fi
  echo "$REPLY"
done
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.