For some monitoring purposes, for a given list of files (that change path daily) I want to launch a tail -f in the background searching for specific strings How do I properly get the exact pid of the tail commands generated by the for loop, so I could kill them later ?
Here's what I'm trying to do which I think gives me the pid of the script and not the tail process.
for f in $(find file...)
do
tail -f $f | while read line
do case $line in
*string_to_search*) echo " $line" | mutt -s "string detected in file : $1" mail@mail.com;
;;
esac
done &
echo $! >> pids.txt
done