I am trying to use a named pipe to monitor the activity of a running shell script. That shell script will write to the pipe that it has "Started" processing. When it has completed processing it will write "Completed" to the pipe. A second script will perform the monitoring and will read the two messages. If the second script does not receive a "Completed" message in 5 minutes it is to send an alert.
So I found this code from the Linux Journal on using a named pipe to communicate between two processes. My immediate attempt is to get the two messages from the pipe and just display a counter as it goes through the loop, but reset back to 0 if the "Completed" message came. Adding the timing was going to be next as I wanted to make sure it was going to continuously poll the pipe for the next message. However, I am not seeing the counter increment. It appears that it waits at the read line from the pipe. Any suggestions as to what I am doing wrong?
#!/bin/bash
pipe=/tmp/testpipe
loopcnt=0
while true
do
echo "count: $loopcnt"
if read line <$pipe; then
if [[ "$line" == 'Started' ]]; then
echo $line
elif [[ "$line" == 'Completed' ]]; then
echo $line
loopcnt=0
fi
fi
((loopcnt=loopcnt+1))
done
read -t
in itself doesn't help as opening the pipe already blocks when the redirection is handled