[Gloucs] "Is the file completed" in bash

Oliver Gorwits oliver.gorwits at computing-services.oxford.ac.uk
Wed Jul 13 11:42:11 BST 2005


On Wednesday 13 July 2005 00:35, Glyn Davies wrote:
> What's the best way in a script of determining that a file has been
> finished being written to before going on to process it? I'm writing
> a script to rename user backup files to something more meaningful but
> obviously, I don't want to rename a file part way through its
> creation.

There's probably better ways of finding this out... but to see if any 
process has a handle on the file you are interested in, perhaps try:

# lsof | grep messages
syslogd    2371   root    1w      REG      253,0   463813    
8766434 /var/log/messages

# ll /proc/*/fd | grep messages
l-wx------  1 root root 64 Jul 13 11:33 1 -> /var/log/messages

sadly though, these both require you to be root, although the former 
could be run via sudo.

be aware that some text editors (such as vi) don't take a handle on the 
file but rather edit a copy and then move that over the file when you 
save, so these techniques might not show user-interactive process 
working on the files.

regards,
oliver.
-- 
Oliver Gorwits, Network Infrastructure Group,
Oxford University Computing Services



More information about the gloucs mailing list