#/bin/bash

# See on :
# http://unix.stackexchange.com/questions/166341/constantly-check-if-file-is-modified-bash
# !!! Need inotify-tools package

INFILE=minicom.cap
OUTFILE=stm32_pid.`date +%Y%m%d-%H%M%S`.log

while inotifywait -q -e modify $INFILE >/dev/null; do
    # do whatever else you need to do
    LAST_LINE=$(tail -n 1 $INFILE)
    DATE=`date +%Y%m%d-%H%M%S`
    echo $(printf "%s %s" "$DATE" "$LAST_LINE") >> $OUTFILE

done
