Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

shell script to process the same files daily and weekly

Posted on 2014-12-03
12
Medium Priority
?
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

715 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