Need an automated pre-defined file pickup method

Hi Gurus,

I need to develop a script which picks the files in a pre-defined order.
The files from monday-friday will be named as abc_01_20130923 as monday's file and abc_02_20130924 as tuesday's..so..so forth till friday's which will be named as abc_05_20130927.It repeats over for the subsequent weeks in the same pattern

The requiremt is that if for instance on tuesday abc_02_20130924 file comes along with monday's abc_01_20130923, the monday's file sgould be copied first into a location and after an hour tuesday's file should be copied to that location.The file is the trigger to the script

I have the following logic in mind:

#!/sh/bin

>> Both the files come into the location

echo $filename >> output

sleep 5(Let both the filenames be written into the output file)

>> while read line

do
   extract the 01, 02,03,04,05 part of the filenames as the case might be.
if two files come ; then
 compare the number part of the two files
   if [ 01<02 ] ; then ( basically a file bearing a smaller number should be sent first.It can 02 < 05/03 < 04.Depends on the day two files have come)
   copy 01 file first to /location
  wait for an hour
   then
   copy 02 file next to /location
   else if only file comes
   copy that file to /location
  done < output

Please can anybody help me out here as i am still new to shell scripting. I use a bourne shell.Thanks

Can you change the filenames to better match your problem? If they were YYYYMMDD_05_abc, for FILE in * would spit them out in ascending date order.

1 Like

No.I am afraid that cannot be done. The filename remains fixed. I was thinking it can be much easier to check the file on the code basis "01" , "02" etc rather than on the date basis. I am not sure.But that is what i was thinking.
Any improvement to the above logic is please greatly appreciated.

---------- Post updated at 01:40 AM ---------- Previous update was at 12:39 AM ----------

Corona is there a way we can just extract the "01"/"02" etc part of the file by reading the output file and use this as a criterion to compare between an older and a newer file in the week please?

You could try ls -v if your system provides that: man ls :