Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 20 Jun 2018, 14:00
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
Code that effectively does what inotify does!
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [1 Post]  
Author Message
stemsee

Joined: 27 Jun 2013
Posts: 2205
Location: In The Way

PostPosted: 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.
Back to top
View user's profile Send private message MSN Messenger 
Display posts from previous:   Sort by:   
Page 1 of 1 [1 Post]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

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


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1042s ][ Queries: 11 (0.0223s) ][ GZIP on ]