Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to write an Unix Shell Script tran.sh that moves the csv input files from /exp/files folder to /exp/ready directory. The csv input files are written to /exp/files folder by an SFTP server whose behavior I cannot trivially change.

In tran.sh shell script I need to ensure before doing a move of that csv input file from /exp/files directory no longer any other process is writing to the file. How can I move it?

share|improve this question

1 Answer 1

lsof might be what you want (it is after all, the command to list open files). If your files have a known naming convention, run an lsof <filename> against it to check if it is indeed being used by a process. If it isn't, lsof will return a non-zero return code.

share|improve this answer
    
Please note: If you want to check if the file is being written to by another user, you'll need to run lsof (or fuser) as root. If you're checking a file on NFS, lsof or fuser will only tell you something when run on the machine from which the file is being written to. –  Emmanuel Joubaud Aug 28 at 9:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.