0

Sure someone out there can point out what i'm doing wrong... Cant get this to loop correctly through all the results of the find command. running this in AIX.

Essentually i'd like it to find all the files 1 day old and then cat them all into one file.

#! /bin/sh

p1='/MSS-Storage/data/DataExport/runlog'
p2='/MSS-Storage/apps/scripts'
x=1

find $p1/* -mtime -1 -type f >> $p2/tmp.txt

for period in `cat $p2/tmp.txt`

do
        echo "************************Export $x*************************/
                *************************************************" > $p2/`date +summary.\%Y\%m\%d_\%H\%M.log`
        cat $period > $p2/`date +summary.\%Y\%m\%d_\%H\%M.log`
                x=$x+1

done
Graham
  • 33
  • 8

1 Answers1

0

I would use a ksh shebang line (without space).
Is MSS-Storage at the root level as suggested by the starting slash?
You append the find results to tmp.txt, this file gets larger every run. I think you want to overwrite the file. You can redirect the find results skipping the tmp.txt file.
Within the loop you should use >> (you do not want to overwrite your results), but I will redirect outside the loop.
The date command should be outside the loop (only determine the date once)
Adding 1 to x can be done with (( x = x + 1 ))
This will add up to:

#!/bin/ksh

p1='/MSS-Storage/data/DataExport/runlog'
p2='/MSS-Storage/apps/scripts'

x=1

find $p1/* -mtime -1 -type f | while read period; do
   echo "************************Export $x*************************/
      *************************************************" 
   cat $period
   (( x = x + 1 ))
done > $p2/summary.$(date +'%Y%m%d_%H%M').log
Walter A
  • 19,067
  • 2
  • 23
  • 43