<?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 script - check file before copy in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172187#M663052</link>
    <description>Hi,&lt;BR /&gt;below script transfer file, the file creates by application and start writting data to it and it takes 1 hour to complete, and every two hour create new file, the problem I have I need to copy the file only when it is complete written to it or if it is not 0 size.&lt;BR /&gt;--------my script ---------------------&lt;BR /&gt;#&lt;BR /&gt;cd /NRT/NRT_src&lt;BR /&gt;ls *NR_BHRBT_* | read LINE&lt;BR /&gt;if [ $? = 0 ]&lt;BR /&gt; then&lt;BR /&gt;        mv $LINE /NRT_backup&lt;BR /&gt;   date | read sdate&lt;BR /&gt;   &lt;BR /&gt;        cd /NRT_backup&lt;BR /&gt;        scp $LINE BHRBTF@111.111.11.11:/&lt;BR /&gt; if [ $? -eq 0 ];then&lt;BR /&gt;   date | read edate&lt;BR /&gt;   echo Finish copy $LINE $sdate &amp;gt;&amp;gt;/NRT_daily_out.log&lt;BR /&gt; else&lt;BR /&gt;   echo Failed copy of $LINE "$edate" &amp;gt;/NRT_faild.log&lt;BR /&gt; fi&lt;BR /&gt;fi&lt;BR /&gt;-----------------------------------&lt;BR /&gt;Regards,&lt;BR /&gt;Ahmed</description>
    <pubDate>Tue, 28 Apr 2009 10:29:06 GMT</pubDate>
    <dc:creator>Ahmed_58</dc:creator>
    <dc:date>2009-04-28T10:29:06Z</dc:date>
    <item>
      <title>script - check file before copy</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172187#M663052</link>
      <description>Hi,&lt;BR /&gt;below script transfer file, the file creates by application and start writting data to it and it takes 1 hour to complete, and every two hour create new file, the problem I have I need to copy the file only when it is complete written to it or if it is not 0 size.&lt;BR /&gt;--------my script ---------------------&lt;BR /&gt;#&lt;BR /&gt;cd /NRT/NRT_src&lt;BR /&gt;ls *NR_BHRBT_* | read LINE&lt;BR /&gt;if [ $? = 0 ]&lt;BR /&gt; then&lt;BR /&gt;        mv $LINE /NRT_backup&lt;BR /&gt;   date | read sdate&lt;BR /&gt;   &lt;BR /&gt;        cd /NRT_backup&lt;BR /&gt;        scp $LINE BHRBTF@111.111.11.11:/&lt;BR /&gt; if [ $? -eq 0 ];then&lt;BR /&gt;   date | read edate&lt;BR /&gt;   echo Finish copy $LINE $sdate &amp;gt;&amp;gt;/NRT_daily_out.log&lt;BR /&gt; else&lt;BR /&gt;   echo Failed copy of $LINE "$edate" &amp;gt;/NRT_faild.log&lt;BR /&gt; fi&lt;BR /&gt;fi&lt;BR /&gt;-----------------------------------&lt;BR /&gt;Regards,&lt;BR /&gt;Ahmed</description>
      <pubDate>Tue, 28 Apr 2009 10:29:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172187#M663052</guid>
      <dc:creator>Ahmed_58</dc:creator>
      <dc:date>2009-04-28T10:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: script - check file before copy</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172188#M663053</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;You could use 'fuser' to look for any process(es) still using the file and when none, perform your copy:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;while true do&lt;BR /&gt;    PIDS=$(fuser ${FILE} 2&amp;gt; /dev/null) #...look for any process using file...&lt;BR /&gt;&lt;BR /&gt;    [ -z "${PIDS}" ] &amp;amp;&amp;amp; break #...no processes, so OK to continue&lt;BR /&gt;&lt;BR /&gt;    sleep 60&lt;BR /&gt;done&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Use the '-s' test for size:&lt;BR /&gt;&lt;BR /&gt;# [ -s ${FILE} ] &amp;amp;&amp;amp; echo "size &amp;gt; 0" || echo "size = 0"&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Apr 2009 10:53:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172188#M663053</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-04-28T10:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: script - check file before copy</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172189#M663054</link>
      <description>Shalom Ahmed,&lt;BR /&gt;&lt;BR /&gt;See the if -z and/or -f parameter.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.bsdnexus.com/viewtopic.php?id=1272" target="_blank"&gt;http://forums.bsdnexus.com/viewtopic.php?id=1272&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.linuxquestions.org/questions/linux-server-73/shell-script-problem.-check-file-already-exists-601105/" target="_blank"&gt;http://www.linuxquestions.org/questions/linux-server-73/shell-script-problem.-check-file-already-exists-601105/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.unix.com/shell-programming-scripting/32809-have-shell-script-check-file-exist-before-processing-another-file.html" target="_blank"&gt;http://www.unix.com/shell-programming-scripting/32809-have-shell-script-check-file-exist-before-processing-another-file.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Tue, 28 Apr 2009 10:56:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172189#M663054</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2009-04-28T10:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: script - check file before copy</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172190#M663055</link>
      <description>&amp;gt;only when it is complete written to it or if it is not 0 size.&lt;BR /&gt;&lt;BR /&gt;The first is hard to determine unless you are root and can use JRF's fuser.&lt;BR /&gt;&lt;BR /&gt;If there is something at the end if the file you can check, you can use tail and grep.</description>
      <pubDate>Tue, 28 Apr 2009 15:32:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172190#M663055</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-04-28T15:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: script - check file before copy</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172191#M663056</link>
      <description>one other possibility, if you can't use fuser, would be to check the file size (ls -l or ?), wait for a bit then check it again to see if its changed...&lt;BR /&gt;&lt;BR /&gt;but valid values of "wait for a bit" might be hard to determine.....</description>
      <pubDate>Tue, 28 Apr 2009 19:24:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172191#M663056</guid>
      <dc:creator>OldSchool</dc:creator>
      <dc:date>2009-04-28T19:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: script - check file before copy</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172192#M663057</link>
      <description>&lt;!--!*#--&gt;&amp;gt; [...] the file creates by application [...]&lt;BR /&gt;&lt;BR /&gt;Some applications are more helpful than&lt;BR /&gt;others in cases like this.  For example, when&lt;BR /&gt;Info-ZIP Zip creates an archive (say,&lt;BR /&gt;"fred.zip"), it normally uses a temporary&lt;BR /&gt;file name (like "ziXXXXXX", with help from&lt;BR /&gt;mkstemp()).  Then, when the work is done (and&lt;BR /&gt;if all went well), it renames the temporary&lt;BR /&gt;file to the requested name ("ziXXXXXX" to&lt;BR /&gt;"fred.zip", in this case).  So, if you can&lt;BR /&gt;see "fred.zip", then you can be pretty sure&lt;BR /&gt;that it's all there.&lt;BR /&gt;&lt;BR /&gt;Of course, this requires some extra work by&lt;BR /&gt;the application.</description>
      <pubDate>Tue, 28 Apr 2009 21:11:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172192#M663057</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-04-28T21:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: script - check file before copy</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172193#M663058</link>
      <description>thanks to all, the script is working now with your help.</description>
      <pubDate>Wed, 29 Apr 2009 10:01:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-check-file-before-copy/m-p/5172193#M663058</guid>
      <dc:creator>Ahmed_58</dc:creator>
      <dc:date>2009-04-29T10:01:26Z</dc:date>
    </item>
  </channel>
</rss>

