views:

115

answers:

2

I am writing a script that will look in a custom reports directory, copy it to a working folder, along with the data files that it will look at, runs the report, zips the newly created files, and uploads them to another server.

The problem that I'm running into is that I don't know what the newly created files will be called at all (nor file extensions). I was wondering if there was a way of zipping or finding out what the newly created files were (as compared to before the report was run and after).

I would look at the timestamps and just move the newest files somewhere to zip them, however the reports that are being run could potentially create multiple files at different times (such as a phone report file first, then after, a data report file).

Any ideas on how I could accomplish this?

+1  A: 

You should be able to do something like:

touch report_start
./run_report
for i in `ls -Rt`; do
    echo $i | grep report_start
    if [ $? -eq 0 ]; then
        break    
    fi
    cp $i reports
done
rm reports/report_start
tar xvzf reports.tar.gz reports
rm report_start

which loops through every file in the directory, seeing if they are newer than a file you created before you ran the report, and then makes a tarball of the results.

Tynan
Never parse ls: http://mywiki.wooledge.org/ParsingLs - you can do "for i in *" - If you need recursion, use find. You don't need to rm reports/report_start since it's not -nt itself and won't get copied.
Dennis Williamson
Yeah, I forgot about -newer with find - I thought the only way to sort by time would be with -t.
Tynan
+2  A: 

Similar idea with Tynan's:

touch report_start
./run_report
find $working_dir -type f -newer report_start | tar czf $archive
rm report_start
florin
find is one crazy swiss-army beast of a tool. Had no idea about the newer param. Thanks!
seth
Wow, I never knew about find. Thanks guys, I really appreciate it. :)
Dropped.on.Japan
Hmm, just as I thought this would work. For some reason it isn't seeing the touched file as older than the files that were created. I've put sleep counters on there, thinking that it may be because if it's less than a second the timestamp would look the same, but that didn't work either. Right now I'm going to touch all the files back to a earlier date to see if that works, but I don't know if this will fix it.
Dropped.on.Japan
I've verified that the timestamp is newer for the created files. Here is my find command: find /home/webreports/data/$tag -newer "report_start" -type "f" -print Just running this command (without trying to zip anything) doesn't return anything.
Dropped.on.Japan