Link to home
Start Free TrialLog in
Avatar of kalyangkm
kalyangkmFlag for United States of America

asked on

shell script to process the same files daily and weekly

Hi Experts

I have a scenario where in the there are 2 receivers to which the file from source directory needs to be sent and the receiver is determined based on the timestamp on the file or more precisely depending on the day, and the same filename scehma is used in source to send to both the receivers.  

   FYI, The middleware I am using provides a file adapter which has options to include direcotry paths, include shell scripts to run before and after the file processing. I can use this File adapters and both sender and receiver sides. All I need is to finalize a logic for this approach and implement it in iSeries shell script.

   For example if the source file in /src directory is FileName12022014 this needs to be sent to Receiver1 /rec1 directory only ----and in the same way all the files which are placed untill the 6th day in this case FileName12072014 should also be placed only in receiver1 directory /rec1. But the FileName12082014 which is the 7th day file should be sent to both the Receiver 1 and Receiver 2. I see we wont be able to achieve this without the shell script in the file adapter, but would appreciate suggestions on the best way to achieve this.
 
Regards
Kalyan
Avatar of NVIT
NVIT
Flag of United States of America image

Who receives on the 14'th day, the 21st day, etc?
Avatar of kalyangkm

ASKER

It's both Reciver 1 and receiver 2 directories. So basically we can take any one day of the week say Friday to be the day when both Reciver 1 and Reciver 2 directorieS receive. The rest of th week days only Receiver 1 directory should.
Kalyangkm,
I didn't read carefully. Your tag showed Windows Operating System but your post shows you need an iSeries shell script. I'm not familiar with iSeries scripting.
NewVillageIT,

It is fine, please provide the solution in windows. I need the idea and logic. Though I have done some scripting on Unix I am still amateur in any shell scripting language. I can post another question later if I have issues with iSeries.
Make this .bat file:
REM Change Day7 to your designated 7th day. Either Mon Tue Wed Thu Fri Sat Sun
REM .
REM SourceFile is passed as an argument.
set Day7=Sun
set SourceFile=%1
set Today=%date:~0,3%
set Send2x=
if /i %Today%==%Day7% set Send2x=1
copy %SourceFile% receiver1
if %Send2x%==1 copy %SourceFile% receiver2

Open in new window

A leaner version:
set Day7=Sun
set SourceFile=%1
set Today=%date:~0,3%
copy %SourceFile% receiver1
if /i %Today%==%Day7% copy %SourceFile% receiver2

Open in new window

Hi NewVIllageIT

So this what I understood and this what I am planning to do with my middleware tool.

According to you the script checks source directory (which you haven't specified for simplicity of understanding) for files with todays date and if the todays date is not Sun (which is our week end day or seventh day) then the file is put in receiver 1 directory (which I think you haven't specified for understanding purpose to keep things simple). and if the date is todays date and sunday then file is put in Receiver 1 directory as well as Receiver 2 Directory (same here the directory is not specified).


Dont we need to take a temp folder in the source directory and archive to avoid same file being processed to the target directories?

So if the above understanding is right, then I can use my middleware as follows where in I will be using 1 sender file adapter to run the script and pick up the files from Receiver 1 directory for further processing like mapping transformations etc and the other sender file adapter to pick up the 7th day file from receiver 2 directory and processed further.
avoid same file being processed to the target directories?
Yes. We can make the archive folder at the start. Then place the MOVE after the COPY command.

if not exist c:\archivefolder md c:\archivefolder
set Day7=Sun
set SourceFile=%1
set Today=%date:~0,3%
copy %SourceFile% receiver1
if /i %Today%==%Day7% copy %SourceFile% receiver2
move %SourceFile% c:\archivefolder

Open in new window

Thank You . I will try it and will reply back. Please give me 2 to 3 days.
Hi NewVillageIT,

In the following code, how should I write the systax to include the source file in directory C:\Users\gollak\Desktop\Batch_Testing\Src\out and the scource file name in the directory is "ABCYYYYY" where YYYY is date, for example ABC12022014.txt, ABC12022014.txt etc...

And also how should I run this to test it. Is it only through Task scheduler of WIndows?

if not exist C:\Users\XXXX\Desktop\Batch_Testing\Src\archive md C:\Users\XXXX\Desktop\Batch_Testing\Src\archive
set Day7=Sun
set SourceFile=%1
set Today=%date:~0,3%
copy %SourceFile% C:\Users\XXXX\Desktop\Batch_Testing\Receiver1
if /i %Today%==%Day7% copy %SourceFile% C:\Users\XXXX\Desktop\Batch_Testing\Receiver2
move %SourceFile% C:\Users\XXXX\Desktop\Batch_Testing\Src\archive
Kalyangkm,

,,,how should I write the systax to include the source file in directory ... and the scource file name in the directory,,,
I'm not following your meaning. Let me try to explain...

The code I posted would be saved to a file with a name like CopyFiles.bat (or WhateverNameYouLike.bat).

In set SourceFile=%1, the %1 is the source filename passed to CopyFiles.bat, for example:
CopyFiles.bat C:\Users\gollak\Desktop\Batch_Testing\Src\out\ABC12022014.txt

Open in new window


To test run the code, you can run it in Task Scheduler or a CMD shell. It is usually best to run it in a CMD shell. At least until you are certain it works without errors. Then, you can use the Task Scheduler if desired:
1. Run a CMD shell
2. Type CopyFiles.bat C:\Users\gollak\Desktop\Batch_Testing\Src\out\ABC12022014.txt

Let me know if you need more help.
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial