I need to read and write serveral files in serveral remote machines. Mainly using java, and shell is also ok.
At first, I want to ssh to the remote machine and read/write file, and using Channel.lock()
to lock the file. But I found it difficult to implement...
Then, I have another way:
For every remote file, such as FileA, provide a shell script, such as changFileA.sh on the remote machine in advance.
Thus, I can concurrent execute the tasks. Each task contained the following info.
machineIp, filePath, changeScriptPath, changeParam
But the question is that, there will be more than one task to modify the same file at the same time.
How I can lock it? Only allow one thread to modify the same file?
Thank you.