Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

shell script to process the same files daily and weekly

Posted on 2014-12-03
12
Medium Priority
?
286 Views
Last Modified: 2014-12-06
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
0
Comment
Question by:kalyangkm
  • 7
  • 5
12 Comments
 
LVL 25

Expert Comment

by:NVIT
ID: 40478721
Who receives on the 14'th day, the 21st day, etc?
0
 

Author Comment

by:kalyangkm
ID: 40478945
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.
0
 
LVL 25

Expert Comment

by:NVIT
ID: 40479010
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kalyangkm
ID: 40479257
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.
0
 
LVL 25

Expert Comment

by:NVIT
ID: 40479462
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

0
 
LVL 25

Expert Comment

by:NVIT
ID: 40479513
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

0
 

Author Comment

by:kalyangkm
ID: 40479903
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.
0
 
LVL 25

Expert Comment

by:NVIT
ID: 40479909
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

0
 

Author Comment

by:kalyangkm
ID: 40480134
Thank You . I will try it and will reply back. Please give me 2 to 3 days.
0
 

Author Comment

by:kalyangkm
ID: 40482206
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
0
 
LVL 25

Expert Comment

by:NVIT
ID: 40482388
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.
0
 
LVL 25

Accepted Solution

by:
NVIT earned 2000 total points
ID: 40484674
I hope things are working for you, Kalyangkm.

To process multiple files at once in c:\Users\gollak\Desktop\Batch_Testing\Src\out, like ABC12022014.txt, ABC12032014.txt etc...

CopyFiles "c:\Users\gollak\Desktop\Batch_Testing\Src\out\*.*"

Open in new window

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question