<?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 Simple C program to process a UNIX file? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/simple-c-program-to-process-a-unix-file/m-p/4871473#M707330</link>
    <description>I want to write a C program that constantly loops around and checks the "last modified" date of a given file.  &lt;BR /&gt;&lt;BR /&gt;This file is a data file that is randomly ftp'd to me by someone else (always to the same place and with the same name).&lt;BR /&gt;&lt;BR /&gt;I want to process the file if it is "new" ie if I haven't processed it before.&lt;BR /&gt;&lt;BR /&gt;I have no idea how to do this easily.&lt;BR /&gt;&lt;BR /&gt;Anyone have any ideas?  many thanks....&lt;BR /&gt;&lt;BR /&gt;Pete</description>
    <pubDate>Fri, 19 Nov 2004 13:41:38 GMT</pubDate>
    <dc:creator>Peter Kempner</dc:creator>
    <dc:date>2004-11-19T13:41:38Z</dc:date>
    <item>
      <title>Simple C program to process a UNIX file?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/simple-c-program-to-process-a-unix-file/m-p/4871473#M707330</link>
      <description>I want to write a C program that constantly loops around and checks the "last modified" date of a given file.  &lt;BR /&gt;&lt;BR /&gt;This file is a data file that is randomly ftp'd to me by someone else (always to the same place and with the same name).&lt;BR /&gt;&lt;BR /&gt;I want to process the file if it is "new" ie if I haven't processed it before.&lt;BR /&gt;&lt;BR /&gt;I have no idea how to do this easily.&lt;BR /&gt;&lt;BR /&gt;Anyone have any ideas?  many thanks....&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Fri, 19 Nov 2004 13:41:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/simple-c-program-to-process-a-unix-file/m-p/4871473#M707330</guid>
      <dc:creator>Peter Kempner</dc:creator>
      <dc:date>2004-11-19T13:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Simple C program to process a UNIX file?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/simple-c-program-to-process-a-unix-file/m-p/4871474#M707331</link>
      <description>The key to what you are trying to do is the stat() system call. Man 2 stat for details but doing this in C is drastic overkill. Perl has the stat function that is based on the underlying system call and will easily handle this task:&lt;BR /&gt;&lt;BR /&gt;I'll attach a Perl Script that will do this quite easily and the rest can be a simple shell script:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;TARGET="/xxx/yyy/myfile"&lt;BR /&gt;DELAY=300 # seconds&lt;BR /&gt;&lt;BR /&gt;typeset -i LASTMTIME=0&lt;BR /&gt;typeset -i STAT=0&lt;BR /&gt;&lt;BR /&gt;while [[ ${STAT} -eq 0 ]]&lt;BR /&gt;  do&lt;BR /&gt;    MTIME=$(fileage.pl -m -e ${TARGET})&lt;BR /&gt;    STAT=${?}&lt;BR /&gt;    if [[ ${STAT} -eq 0 ]]&lt;BR /&gt;      then&lt;BR /&gt;        if [[ ${LASTMTIME} -ne ${MTIME} ]]&lt;BR /&gt;          then&lt;BR /&gt;            if [[ ${LASTMTIME} -ne 0 ]]&lt;BR /&gt;              then&lt;BR /&gt;                # yor actual processing goes here&lt;BR /&gt;              fi&lt;BR /&gt;            LASTMTIME=${MTIME}&lt;BR /&gt;          fi&lt;BR /&gt;        sleep ${DELAY}&lt;BR /&gt;      fi&lt;BR /&gt;   done&lt;BR /&gt;exit ${STAT}&lt;BR /&gt;&lt;BR /&gt;Invoke the perl script, fileage.pl w/o arguments for full usage. &lt;BR /&gt;</description>
      <pubDate>Fri, 19 Nov 2004 14:04:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/simple-c-program-to-process-a-unix-file/m-p/4871474#M707331</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-11-19T14:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: Simple C program to process a UNIX file?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/simple-c-program-to-process-a-unix-file/m-p/4871475#M707332</link>
      <description>A minimal "C" example.&lt;BR /&gt;Needs at least somem errno handling.&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;struct stat buf;&lt;BR /&gt;time_t   st_ctime_last;&lt;BR /&gt;main (int argc, char *argv[])&lt;BR /&gt;{&lt;BR /&gt;while (!stat(argv[1], &amp;amp;buf)) {&lt;BR /&gt;  if (buf.st_ctime &amp;gt; st_ctime_last) {&lt;BR /&gt;    printf ("!\n");&lt;BR /&gt;    st_ctime_last = buf.st_ctime;&lt;BR /&gt;    } else {&lt;BR /&gt;    printf (".\n");&lt;BR /&gt;    }&lt;BR /&gt;  sleep (5);&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;/SYS&gt;&lt;/SYS&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Fri, 19 Nov 2004 14:29:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/simple-c-program-to-process-a-unix-file/m-p/4871475#M707332</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-11-19T14:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Simple C program to process a UNIX file?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/simple-c-program-to-process-a-unix-file/m-p/4871476#M707333</link>
      <description>Many thanks to both contributers.  This forum never ceases to amaze me.&lt;BR /&gt;&lt;BR /&gt;.. The really good side of human nature</description>
      <pubDate>Fri, 19 Nov 2004 14:44:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/simple-c-program-to-process-a-unix-file/m-p/4871476#M707333</guid>
      <dc:creator>Peter Kempner</dc:creator>
      <dc:date>2004-11-19T14:44:53Z</dc:date>
    </item>
  </channel>
</rss>

