stemsee
Joined: 27 Jun 2013 Posts: 2572 Location: In The Way
Posted: Thu 24 May 2018, 06:51 Post subject:
Code that effectively does what inotify does!
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:
killall -9 inotifywait
while inotifywait -e close_write /tmp/ap
do
bash -c passwordfn
done
then i changed to this
Code:
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:
while true
do
watch -d -g ls -t -lR /tmp/ap && bash -c passwordfn
sleep 1
done
and this ...
Code:
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:
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.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum