bash - File Lock on Linux -
so there 2 scripts: , b, both want write same file. it's possible both scripts want write file @ same time. how can lock file? while script writing file, script b has wait till file unlocked.
i tried this:
while [ -f $lock ] sleep 0.1 done touch $lock #action rm $lock
problem script above it's possible, both of , b looking $lock @ same time, , cant find't start writing. help?
try this:
script open file set attribute chattr +i test.txt
, after script done use chattr -i test.txt
.
for example:
script a
chattr +i test.txt tail -n 50 /var/log/maillog > test.txt chattr -i test.txt
script b
chattr +i test.txt tail -n 50 /var/log/messages > test.txt chattr -i test.txt
Comments
Post a Comment