I don't quite know what I'm doing, so this simple script is proving a challenge.
Here is some pseudo code that doesn't work yet:
if tail -1 "WORKING.txt" >/dev/null | egrep "^NMBR=*" > /dev/null
then
curl -k 'http://www.myserver.com/log.cgi?input=$?'
echo "hi there"
fi
Purpose: Continuously monitor file "WORKING.txt" and check each new line as it is appended for lines that begin "NMBR=(number)" then take the value of the line and send it via curl to my web server as a variable.
That does work, and it's more elegant that my tail solution... BUT it doesn't continuously monitor the log. I would have to put it inside of a while loop and have it sleep. I like tail because it only updates when the file has been modified, rather than every second which is what I would have to do with while.
The problem is that more than 1 line could have been added while your script slept
The best is to perform (Pseudo-code) :
line count (wc -l), calc the difference with previous count, tail the difference from your file, set your previous-count-variable to the new count, sleep, loop.
OLD=0
while true
do
COUNT=$(wc -l < $FILE)
DIFF=$((COUNT-OLD))
if [ $DIFF -gt 0 ]
then
tail -n $DIFF $FILE
OLD=$COUNT
elif [ $DIFF -lt 0 ] # Can happen (logrotate...)
OLD=0
continue
fi
sleep 1
done