Solved

shell script to process the same files daily and weekly

Posted on 2014-12-03
12
244 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 23

Expert Comment

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

Author Comment

by:kalyangkm
Comment Utility
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 23

Expert Comment

by:NVIT
Comment Utility
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
 

Author Comment

by:kalyangkm
Comment Utility
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 23

Expert Comment

by:NVIT
Comment Utility
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 23

Expert Comment

by:NVIT
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:kalyangkm
Comment Utility
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 23

Expert Comment

by:NVIT
Comment Utility
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
Comment Utility
Thank You . I will try it and will reply back. Please give me 2 to 3 days.
0
 

Author Comment

by:kalyangkm
Comment Utility
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 23

Expert Comment

by:NVIT
Comment Utility
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 23

Accepted Solution

by:
NVIT earned 500 total points
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article covers how to install the Microsoft Windows Operating System (OS). What is covered in this article:  > Different Versions and Editions of the Windows OS  > Upgrading versus Fresh Installation of the OS           - Steps to take pr…
This is a little timesaver I have been using for setting up Microsoft Small Business Server (SBS) in the simplest possible way. It may not be appropriate for every customer. However, when you get a situation where the person who owns the server is i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now