Summary of "listing files bet 2 dates"

Manoj Joshi manoj at hpldsla.sid.hp.com
Fri Oct 26 03:49:33 AEST 1990


I got a lot of interesting mail from people on the net which was 
very hclosest way to solve this problem. I found that somehow the mtime
and ctime options of find are not to accurate. Besides, I founI had to write a shell script anyway which find. So I decided instead to write a shell script whicfiles in a dir, and uses a c program to check itime interval condition. The performance was great, it's lightning 
fast on my 12 mip w/s. Anyway, I have included these here for peoplcuriosity. I can mbut here it is only on an experimental basis. (For instance, I think 
the comparison loop should exit as soon as the first mismatch is founsince, the -t option of ls ensures the files are scanned in the 
chronological order.)

With this script I could archive files between two dates. And it is 
accurate about that. It will not be too hard to implement exact times. 
In the long run, I would the files in the sam

/*********************************************************************/
/*  EXAMPLE LISTING */
/*********************************************************************/

#!/bin/ksh
# Declaration of variables

hostName=$1
instName=$2
fromDate=$3
toDate=$4
selectList=""
searchDir=$DATA_DIR/$hostName/hpchem/$instName/data
currentDir=`pwd`
cd $searchDir

list=`ls -Rrt`
for currentFido
   $currentDir/selectFi   result=$?
   if [ result -eq 0 ]
   then
      selectList="$selectList $currentFi   fi
done
echo tar -cvf /dev/update.src $selectList
cd $currentDir


/*********************************************************************/
/*  EXAMPLE LISTING */
/*********************************************************************/


#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>

int selectFile(file, fromDate, toDate)
   char* file; 
   char* fromDate; 
   char* toDate;
   { /* selectFi   struct stat *buf;
   struct tm *timeptr1;
   struct tm *timeptr2;
   time_t ftime;
   time_t ttime;

   int fDate = (int)atoi(fromDate);
   int tDate = (int)atoi(toDate);

   buf = (struct stat *)malloc(sizeof(struct stat));
   memset(buf, '\0', sizeof(struct stat));

   if (stat(file, buf))
      {
      perror("stat");
            };

   timeptr1 = (struct tm *)malloc(sizeof(struct tm));
   memset(timeptr1, '\0', sizeof(struct tm));
   timeptr1->tm_sec = 0;
   timeptr1->tm_min = 0;
   timeptr1->tm_hour = 0;
   timeptr1->tm_mday = fDate%100;
   timeptr1->tm_mon = (fDate/100)%100-1;
   timeptr1->tm_year = (fDate/10000)%100;
   timeptr1->tm_wday = 0;
   timeptr1->tm_yday = 0;
   timeptr1->tm_isdst = -1;
    
   timeptr2 = (struct tm *)malloc(sizeof(struct tm));
   memset(timeptr2, '\0', sizeof(struct tm));
   timeptr2->tm_sec = 59;
   timeptr2->tm_min = 59;
   timeptr2->tm_hour = 23;
   timeptr2->tm_mday = tDate%100;
   timeptr2->tm_mon = (tDate/100)%100-1;
   timeptr2->tm_year = (tDate/10000)%100;
   timeptr2->tm_wday = 0;
   timeptr2->tm_yday = 0;
   timeptr2->tm_isdst = -1;

   if ((ftime = mktime(timeptr1)) == (time_t)-1)
      {
      perror("mktime");
            };

   if ((ttime = mktime(timeptr2)) == (time_t)-1)
      {
      perror("mktime");
            };

#ifdef TEST
   printf("From Date : %s\n", asctime(timeptr1));
   printf("To Date : %s\n", asctime(timeptr2));
   printf("Fi#endif

   if ((buf->st_mtime >= ftime) && (buf->st_mtime <= ttime))
         else     
   } /* selectFi
int main(argc, argv)
   int argc;
   char** argv;
   { /* main */
   if (argc != 4)
      {
      fprintf(stderr, 
      "Usage: selectFi      exit(1);
      };
    
   if (!(selectFile(argv[1], argv[2], argv[3])))
      {
#ifdef TEST
      printf("%s not selected\n", argv[1]);
#endif
      return(0);
      }
   else 
   } /* main */
#! rnews 2842
Path: rebel!gatech!ncar!husc6!encore!mpheters
From: mpheters at encore.Subject: Re: AMC -- sketchy update for Wed., Oct. 25



More information about the Comp.unix.questions mailing list