I have a bash script set up to monitor a number of UDP streams and convert it into actionable data. My problem is that I need to set the script to periodically check to see if the stream capture is running and restart it if it isn't.
The challenge is to create a new process name or ID for each stream capture and check to see if it's running.
Here's a watered down version of what I've got. I'm hoping someone can tell me if I'm on the right track or not:
Subscriber () { processName="$1$2$4"; echo "$processName"; pgrep $processName; if [[ $? -ne 0 ]] ; then echo "Subcription for $1 with IP $2 not found, restarting." ; while read -re -t 43200 doc; do <Code to analyze stream> done < <(bash -c "exec -a $processName <Commands to capture stream as JSON doc>") else echo "Subcription for $1 wtih IP $2 found to be running, skipping." ; fi } while read line; do Subscriber $line; done < $flatFile Ideally, I'd like to get a process ID or name for the entire string of commands listed after exec -a, but it currently only taking the first command, which seems to be sort of working, but I'm not confident it will do what I'm wanting it to do.
The flatFile reference is a dynamically updated flatfile listing several hundred streams I'm monitoring.