Solved

shell script to process the same files daily and weekly

Posted on 2014-12-03
12
272 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 24

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 24

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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 

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 24

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 24

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 24

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 24

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 24

Accepted Solution

by:
NVIT earned 500 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
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…

710 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