0

I want a daemon that continuously watches a named pipe for input, and then creates two files: one that contains all the data that went through the named pipe, and one that contains a filtered version of it.

When I run this command from the command line it works as intended, $ACTIONABLE_LOG_FILE is created as a filtered version of $LOG_FILE_BASENAME:

cat $NAMED_PIPE | tee -a "$LOG_FILE_BASENAME" | grep -P -v "$EXCEPTIONS" >> "$ACTIONABLE_LOG_FILE" &

But when I leave the following code running in the background, nothing gets appended to $ACTIONABLE_LOG_FILE:

while true
do
   cat $NAMED_PIPE | tee -a "$LOG_FILE_BASENAME" | grep -P -v "$EXCEPTIONS" >> "$ACTIONABLE_LOG_FILE" &
   wait $!
done

The file $ACTIONABLE_LOG_FILE gets created, but nothing gets appended to it. What's going on here?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Diego Puertas
  • 87
  • 1
  • 5
  • What's your working directory when you run the script? – Cyrus Aug 26 '15 at 20:45
  • How is the while loop executed? From a script with `./yourscript` in the terminal you successfully ran the command? Copy-pasted as is into the terminal? Started by cron or rc.d or something else? – that other guy Aug 26 '15 at 20:52
  • Useless use of `cat`: `tee ... < "$NAMED_PIPE"`. – chepner Aug 26 '15 at 21:03
  • 1
    Does the $LOG_FILE_BASENAME file get created? Does it get new data? What is the value of each of the variable in the script; how do you know? Is $EXCEPTIONS actually just a shell variable, not an environment variable? Since you've not shown semi-plausible values for the 4 variables you use, but a mistake in one or more of them could easily break the script, we have to guess that the mistake is yours, rather than in the commands themselves (the shell, or cat or tee or grep). Create an MCVE ([How to create a Minimal, Complete, and Verifiable Example?](http://stackoverflow.com/help/mcve)) – Jonathan Leffler Aug 26 '15 at 22:26
  • $LOG_FILE_BASENAME gets created and receives new data. All the variables have the correct value. – Diego Puertas Aug 28 '15 at 14:10

1 Answers1

1

My suspicion would be that when daemonized, you do not have a full environment available, and hence no $PATH. The full path to the command (likely /usr/bin/tee) might help a lot. You can confirm that locally with which tee.

Alister Bulman
  • 34,482
  • 9
  • 71
  • 110