I want to create a bash script to determine if my file is already opened by another user.
I have already tried with lsof
but it didn't work as i wanted. The files can have different types of extension e.g. txt,pl,conf,cfg etc.
Can someone help me?
I have one server with many file .conf. If i write in one file, i can't know if another user write in the same file too. So i'd like to build a script that let me know that.
I tried something like this lsof | grep MyFile
or lsof /root/blabla/myfolder/myfile
etc. Maybe i don't understand the use of this tool.
i'll try to explain better my problem. There are many users that can be modify .conf file. If two users work on same file, the last saving overwrite the change made from the other user.
My script wants to warn the users that the file is already opened by another user and maybe open the file in read-only mode.
I already tried with ps aux
(thx for the hint) but i can't estimate if my file was recently closed.
lsof
?lsof
? i mean what have you tried ?