Problems with find's -newer Flag

I am writing a script that looks in a reports directory, copies a specified script to a working folder, copies some data files into the working folder, runs the report, zips the new files, then uploads them.

Right now to determine what files to zip (as I don't know how many report files there will be, what size, or what they are going to be called), I'm using 'find'.

So basically this is what I have so far:

touch report_start #Marker before files are created

touch -t 200201311759.30 *

yes | runjob $repname > /dev/null

pwd

find /home/webreports/data/$tag -newer "report_start" -type f -print # | zip $study -@  #Zip the files that are newer than report_start

The problem seems to be that find doesn't return anything! When I comment out the zip function, nothing prints out. If I were to search for a name I get file names. Am I missing something, or is the -newer flag not working?

An ls command.

ls --time-style='+%d-%m-%Y %H:%M:%S' -l
total 16668
-rw-rw-rw-  1 cfmc cfmc 1348372 31-01-2002 17:59:30 fd9006y.db
-rw-rw-rw-  1 cfmc cfmc 3620864 31-01-2002 17:59:30 fd9006y.fnx
-rw-rw-rw-  1 cfmc cfmc 9650176 31-01-2002 17:59:30 fd9006y.fny
-rw-rw-rw-  1 cfmc cfmc   12888 31-01-2002 17:59:30 fd9006y.fon
-rw-rw-rw-  1 cfmc cfmc 1197688 31-01-2002 17:59:30 fd9006y.qff
-rw-rw-rw-  1 cfmc cfmc   60144 31-01-2002 17:59:30 fd9006y.quo
-rw-r--r--  1 cfmc cfmc  501782 31-01-2002 17:59:30 fd9006y.tr
-rw-rw-rw-  1 cfmc cfmc  167928 30-06-2009 13:54:04 output1.rfl
-rw-rw-rw-  1 cfmc cfmc    1358 30-06-2009 13:54:05 output1.rft
-rw-rw-rw-  1 cfmc cfmc  427232 30-06-2009 13:54:05 output1.sps
-rwxrwxr-x  1 cfmc cfmc     820 31-01-2002 17:59:30 output.spx
-rwxrwxr-x  1 cfmc cfmc     820 31-01-2002 17:59:30 output.spx.backup
-rwxrwxr-x  1 cfmc cfmc     820 31-01-2002 17:59:30 output.spx.backup1
-rwxrwxr-x  1 cfmc cfmc     820 31-01-2002 17:59:30 output.spx.backup2
-rw-rw-rw-  1 cfmc cfmc       0 31-01-2002 17:59:30 report_start

EDIT: Realized that I had put in test code instead of the real command that I used. I will also add that -mtime 1 doesn't seem to work either.

Don't know if the newer flag works or not, since you're not using it in your example. If, however you want to use it, just touch the report_start file (no need to modify the timestamp of the other files) and run

find /home/webreports/data/$tag -newer report_start -print | ...

That should do the trick.

Yeah, I realized that I had put in the wrong code when I initially posted this. I've tried this exact code and this is the output:

/home/webreports/data/65202

Another ls of the directory with the exact code you supplied:

total 17980
-rw-rw-rw-  1 cfmc cfmc 1348372 31-01-2002 17:59:30 fd9006y.db
-rw-rw-rw-  1 cfmc cfmc 3620864 31-01-2002 17:59:30 fd9006y.fnx
-rw-rw-rw-  1 cfmc cfmc 9650176 31-01-2002 17:59:30 fd9006y.fny
-rw-rw-rw-  1 cfmc cfmc   42360 31-01-2002 17:59:30 fd9006y.fon
-rw-rw-rw-  1 cfmc cfmc 1197688 31-01-2002 17:59:30 fd9006y.qff
-rw-rw-rw-  1 cfmc cfmc   60144 31-01-2002 17:59:30 fd9006y.quo
-rw-r--r--  1 cfmc cfmc  508000 31-01-2002 17:59:30 fd9006y.tr
-rw-rw-rw-  1 cfmc cfmc  167928 30-06-2009 15:13:48 output1.rfl
-rw-rw-rw-  1 cfmc cfmc    7469 30-06-2009 15:13:48 output1.rft
-rw-rw-rw-  1 cfmc cfmc  427232 30-06-2009 15:13:48 output1.sps
-rwxrwxr-x  1 cfmc cfmc     820 31-01-2002 17:59:30 output.spx
-rwxrwxr-x  1 cfmc cfmc     820 31-01-2002 17:59:30 output.spx.backup
-rwxrwxr-x  1 cfmc cfmc     820 31-01-2002 17:59:30 output.spx.backup1
-rwxrwxr-x  1 cfmc cfmc     820 31-01-2002 17:59:30 output.spx.backup2
-rw-rw-rw-  1 cfmc cfmc  427232 31-01-2002 17:59:30 putput1.sps
-rw-rw-rw-  1 cfmc cfmc  427232 31-01-2002 17:59:30 qutput1.sps
-rw-rw-rw-  1 cfmc cfmc       0 31-01-2002 17:59:30 report_start
-rw-rw-rw-  1 cfmc cfmc  427232 31-01-2002 17:59:30 rutput1.sps

Exact code that I used:

touch report_start #Marker before files are created

touch -t 200201311759.30 *

yes | runjob $repname > /dev/null

pwd

find /home/webreports/data/$tag -newer report_start -print # | zip $study -@  #Zip the files that are newer than report_start

Just an idea: try replacing

find /home/webreports/data/$tag

with

find /home/webreports/data/$tag/*

Hmm, when I manually put that into the command line it works, but when it's done from my script nothing is printed. I also tried to pipe it into the zip command and it said that there wasn't anything to do (as if it didn't get anything sent into it). I'm going to post the entire script here. Maybe I screwed something up in there that's messing this up.

#!/bin/bash  

export CFMCHOME=/home/cfmc/
export study=$1
export tag=$2
export repname=$3
export specop1=$4
export specop2=$5
export specop3=$6

mkdir /home/webreports/data/$tag

echo "before cp"

cp /home/webreports/custreports/$study/$repname /home/webreports/data/$tag
cd /home/webreports/data/$tag

echo "before copylive"

copylive $study

sed -i.backup -e "s/thisisspecopt1/$specop1/" $repname
sleep .1

sed -i.backup1 -e "s/thisisspecopt2/$specop2/" $repname
sleep .1

sed -i.backup2 -e "s/thisisspecopt3/$specop3/" $repname
sleep .1



touch report_start #Marker before files are created

touch -t 200201311759.30 *

yes | runjob $repname > /dev/null

pwd

find /home/webreports/data/$tag/* -newer report_start -type f -print | zip $study -@  #Zip the files that are newer than report_start





exit 0

Full output of the script:

customreport fd9006y 65202 output.spx
before cp
before copylive
/home/webreports/data/65202

zip error: Nothing to do! (fd9006y.zip)
[cfmc@CFMC2 scripts]$

Can you run theses commands and post their output here...

cd /home/webreports/data/65202     # is this the dir where the files are
touch -t 200201311759.30 report_stat
find . -type f -newer report_start -print

Here's the output:

[cfmc@CFMC2 scripts]$ cd ../data/65202/
[cfmc@CFMC2 65202]$ touch -t 200201311759.30 report_stat
[cfmc@CFMC2 65202]$ find . -type f -newer report_start -print
./output1.rfl
./output1.sps
[cfmc@CFMC2 65202]$

This is what gets me. The command works by itself, but not when I use it via script.

EDIT: It looks like you typed report_stat instead of report_start. Updated output:

[cfmc@CFMC2 65202]$ touch -t 200201311759.30 report_start
[cfmc@CFMC2 65202]$ find . -type f -newer report_start -print
./output1.rfl
./output1.sps
[cfmc@CFMC2 65202]$

EDIT 2:

I figured out another way of getting the new files. Don't worry about the find problem.