Code that effectively does what inotify does!

Under development: PCMCIA, wireless, etc.
Post Reply
Message
Author
stemsee

Code that effectively does what inotify does!

#1 Post by stemsee »

How to watch a file, which needs to be read when having been written to, without using inotifywait, but similar outcome.

I was using this

Code: Select all

killall -9 inotifywait
while inotifywait -e close_write /tmp/ap
do 
	bash -c passwordfn
done
then i changed to this

Code: Select all

function aploop (){
while true
do
read line
if [[ "$line" ]]; then
bash -c passwordfn
unset line
sed -i '1d' /tmp/ap
bash -c aploop
exit
fi
sleep 1
done < /tmp/ap
}; export -f aploop
I am just wondering what other solutions are there??

EDIT: this works too

Code: Select all

while true
do
watch -d -g ls -t -lR /tmp/ap && bash -c passwordfn
sleep 1
done
and this ...

Code: Select all

tail -fn0 /tmp/ap | \
while read line ; do
        echo "$line" | grep "+"
        if [ $? = 0 ]
        then
               bash -c passwordfn
        fi
done
Tis last one can be reduced to

Code: Select all

tail -fn0 /tmp/ap | \
while read line ; do
[[ "$line" ]] && bash -c passwordfn &
done
but really I want to reduce it so that results from tail immediately trigger passwordfn without 'while read line' ... tht would be more effeicient.

Post Reply