<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Test for file open in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/test-for-file-open/m-p/5009299#M99093</link>
    <description>Is there a command to check (in a script) if a file is open? I am writing a script that checks a directory for files which are being either ftp'd from another server, or copied in remotely via samba. The script will move the files to another location for processing. The files can be rather large, so I'd like to put some check to make sure the file is not in the middle of being transferred. I'm thinking of checking new files twice and if the filesize is the same on both checks then its safe to assume the file is complete. Wondering if there is a better. Thought of a "done" file to indicate transfer completion, but that would entail some changes on the sending end.&lt;BR /&gt;Thanks</description>
    <pubDate>Wed, 18 Oct 2006 09:32:37 GMT</pubDate>
    <dc:creator>Luis Toro</dc:creator>
    <dc:date>2006-10-18T09:32:37Z</dc:date>
    <item>
      <title>Test for file open</title>
      <link>https://community.hpe.com/t5/operating-system-linux/test-for-file-open/m-p/5009299#M99093</link>
      <description>Is there a command to check (in a script) if a file is open? I am writing a script that checks a directory for files which are being either ftp'd from another server, or copied in remotely via samba. The script will move the files to another location for processing. The files can be rather large, so I'd like to put some check to make sure the file is not in the middle of being transferred. I'm thinking of checking new files twice and if the filesize is the same on both checks then its safe to assume the file is complete. Wondering if there is a better. Thought of a "done" file to indicate transfer completion, but that would entail some changes on the sending end.&lt;BR /&gt;Thanks</description>
      <pubDate>Wed, 18 Oct 2006 09:32:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/test-for-file-open/m-p/5009299#M99093</guid>
      <dc:creator>Luis Toro</dc:creator>
      <dc:date>2006-10-18T09:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Test for file open</title>
      <link>https://community.hpe.com/t5/operating-system-linux/test-for-file-open/m-p/5009300#M99094</link>
      <description>The command is fuser as in:&lt;BR /&gt; &lt;BR /&gt;fuser /etc/fstab&lt;BR /&gt; &lt;BR /&gt;If the file is open (reading or writing), it will return the process ID(s) that are using it.</description>
      <pubDate>Wed, 18 Oct 2006 09:37:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/test-for-file-open/m-p/5009300#M99094</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2006-10-18T09:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: Test for file open</title>
      <link>https://community.hpe.com/t5/operating-system-linux/test-for-file-open/m-p/5009301#M99095</link>
      <description>&lt;!--!*#--&gt;Hi Luis:&lt;BR /&gt;&lt;BR /&gt;You can test with 'fuser'.  Here's a snippet of code I often use:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;PIDS=`fuser ${FILE} 2&amp;gt; /dev/null`  #...look for any processes...&lt;BR /&gt;if [ ! -z  "${PIDS}" ]; then&lt;BR /&gt;    print -u2 "Error: '${FILE}' is inuse by process(es): ${PIDS}"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 18 Oct 2006 09:37:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/test-for-file-open/m-p/5009301#M99095</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-10-18T09:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Test for file open</title>
      <link>https://community.hpe.com/t5/operating-system-linux/test-for-file-open/m-p/5009302#M99096</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;look for 'lsof' - it can report about open files:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://gatekeep.cs.utah.edu/hppd/hpux/Sysadmin/lsof-4.77/" target="_blank"&gt;http://gatekeep.cs.utah.edu/hppd/hpux/Sysadmin/lsof-4.77/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;..., but I'm not shure, if your approach for 'locking' files is the right one.&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Wed, 18 Oct 2006 09:38:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/test-for-file-open/m-p/5009302#M99096</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-10-18T09:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Test for file open</title>
      <link>https://community.hpe.com/t5/operating-system-linux/test-for-file-open/m-p/5009303#M99097</link>
      <description>Duh.&lt;BR /&gt;I don't know how often I've used the fuser command (when unmounting filesystems), and it didn't cross my mind that I could use it in this instance.&lt;BR /&gt;&lt;BR /&gt;Thanks for the quick replies.</description>
      <pubDate>Wed, 18 Oct 2006 09:41:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/test-for-file-open/m-p/5009303#M99097</guid>
      <dc:creator>Luis Toro</dc:creator>
      <dc:date>2006-10-18T09:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: Test for file open</title>
      <link>https://community.hpe.com/t5/operating-system-linux/test-for-file-open/m-p/5009304#M99098</link>
      <description>If you have lsof installed you can use it to see who is using a file.&lt;BR /&gt;&lt;BR /&gt;The first example here shows what processes have a oracle data file open.&lt;BR /&gt;&lt;BR /&gt;# lsof apd03.dbf&lt;BR /&gt;COMMAND     PID   USER   FD   TYPE     DEVICE  SIZE/OFF NODE NAME&lt;BR /&gt;oraclepro 14739 oracle   34u  VREG 64,0x2000a 524296192    6 apd03.dbf&lt;BR /&gt;ora_dbw0_ 16430 oracle  212uW VREG 64,0x2000a 524296192    6 apd03.dbf&lt;BR /&gt;ora_lgwr_ 16432 oracle  214u  VREG 64,0x2000a 524296192    6 apd03.dbf&lt;BR /&gt;ora_smon_ 16436 oracle  208u  VREG 64,0x2000a 524296192    6 apd03.dbf&lt;BR /&gt;&lt;BR /&gt;If nothing has a file open then you will be returned to the prompt.&lt;BR /&gt;&lt;BR /&gt;# lsof /etc/hosts&lt;BR /&gt;&lt;BR /&gt;So something like this may work:&lt;BR /&gt;&lt;BR /&gt;FILE=filename&lt;BR /&gt;OPEN=$(lsof ${FILE} | wc -l)&lt;BR /&gt;if (( ${OPEN} == 0 )) ; then&lt;BR /&gt;echo "${FILE} is not open"&lt;BR /&gt;else&lt;BR /&gt;echo "${FILE} is open"&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Oct 2006 09:42:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/test-for-file-open/m-p/5009304#M99098</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2006-10-18T09:42:00Z</dc:date>
    </item>
  </channel>
</rss>

