Need an automated pre-defined file pickup method


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need an automated pre-defined file pickup method
# 1  
Old 09-23-2013
Question Need an automated pre-defined file pickup method

Hi Gurus,

I need to develop a script which picks the files in a pre-defined order.
The files from monday-friday will be named as abc_01_20130923 as monday's file and abc_02_20130924 as tuesday's..so..so forth till friday's which will be named as abc_05_20130927.It repeats over for the subsequent weeks in the same pattern

The requiremt is that if for instance on tuesday abc_02_20130924 file comes along with monday's abc_01_20130923, the monday's file sgould be copied first into a location and after an hour tuesday's file should be copied to that location.The file is the trigger to the script

I have the following logic in mind:

#!/sh/bin

[ICODE]>> Both the files come into the location

echo $filename >> output

sleep 5(Let both the filenames be written into the output file)

>> while read line

do
extract the 01, 02,03,04,05 part of the filenames as the case might be.
if two files come ; then
compare the number part of the two files
if [ 01<02 ] ; then ( basically a file bearing a smaller number should be sent first.It can 02 < 05/03 < 04.Depends on the day two files have come)
copy 01 file first to /location
wait for an hour
then
copy 02 file next to /location
else if only file comes
copy that file to /location
done < output


Please can anybody help me out here as i am still new to shell scripting. I use a bourne shell.Thanks

Last edited by vikramgk9; 09-23-2013 at 04:41 PM..
# 2  
Old 09-23-2013
Can you change the filenames to better match your problem? If they were YYYYMMDD_05_abc, for FILE in * would spit them out in ascending date order.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 09-23-2013
No.I am afraid that cannot be done. The filename remains fixed. I was thinking it can be much easier to check the file on the code basis "01" , "02" etc rather than on the date basis. I am not sure.But that is what i was thinking.
Any improvement to the above logic is please greatly appreciated.

---------- Post updated at 01:40 AM ---------- Previous update was at 12:39 AM ----------

Corona is there a way we can just extract the "01"/"02" etc part of the file by reading the output file and use this as a criterion to compare between an older and a newer file in the week please?
# 4  
Old 09-23-2013
You could try ls -v if your system provides that: man ls:
Quote:
-v natural sort of (version) numbers within text
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to write bash script to subdivide a given subnet into a pre-defined number of smaller subnets?

Bash script to subdivide a given subnet into a pre-defined number of smaller subnets. Show network/broadcast address, number of hosts and assign gateway. For example: Input: ./subnetter.sh 192.168.0.0/24 3 Output: 192.168.0.0/128 subnet 192.168.0.0 broadcast 192.168.0.127 gateway... (1 Reply)
Discussion started by: mail2rias
1 Replies

2. Shell Programming and Scripting

How to write bash script to subdivide a given subnet into a pre-defined number of smaller subnets?

Bash script to subdivide a given subnet into a pre-defined number of smaller subnets. Show network/broadcast address, number of hosts and assign gateway. For example: Input: ./subnetter.sh 192.168.0.0/24 3 Output: 192.168.0.0/128 subnet 192.168.0.0 broadcast 192.168.0.127 gateway... (1 Reply)
Discussion started by: mail2rias
1 Replies

3. Shell Programming and Scripting

Need help for automated pickup of file based on a priority

Hi experts, I am facing a problem right now.I have to automate the pickup of files based on a priority.The scenario is as below: 1) There will be files from Mon-Fri with Mon file being named as abc_def_01_YYYYMMDD and Tue file being abc_def_02_YYYYMMDD and so forth till Friday's file which... (1 Reply)
Discussion started by: vikramgk9
1 Replies

4. Shell Programming and Scripting

NOT able to pickup files

Hi, I have two files to pick and excute these ones. File1:DOLFIN.PRL_100.OIB.TLU.001.D20110510.T144948 File2:DOLFIN.PRM_100.OTU.001.D20100726.T050026 date '+%H:%M:%S' SCRIPTS_PATH=/u/dolfin/bin . ${SCRIPTS_PATH}/set_dolfin_env.sh DATA_FILE_NAME=DATA_FILE DATE_FORMAT=`date... (2 Replies)
Discussion started by: shyamu544
2 Replies

5. Shell Programming and Scripting

Is a Perl method defined?

In my code, I know I can write... if ( defined &test_sub ) { test_sub(); } else { print "Subroutine doesn't exist"; } This tests the existence of the test_sub subroutine without actually calling it. If, though, I replace test_sub with a package method... if ( defined... (1 Reply)
Discussion started by: JerryHone
1 Replies

6. Shell Programming and Scripting

logic for executing defined seq in file and cmd in file

I have four files a,b,c,d which need to contain certain in the sequence a, b, c ,d , each file command which needs to be executed, what i m in need is that to executed file and cmd in the defined order and if any of the command FAIL or throw ERROR, it script shud come out... (3 Replies)
Discussion started by: tarunn.dubeyy
3 Replies

7. UNIX for Dummies Questions & Answers

pickup files.

How can I pickup files with a specific date by "ls" command without options? (1 Reply)
Discussion started by: gd2003
1 Replies

8. Shell Programming and Scripting

pickup until last friday files from directory

Freinds, I need help: I need to process number of flat files on weekly basis. My source dir will receive flat files regulary at mid night between 1:00am and 6:00am. When I run my weekly file process it should get only the files which are until last friday (including friday)and move them in... (1 Reply)
Discussion started by: magi
1 Replies

9. Shell Programming and Scripting

pickup file from folder

Hi, Can any body help me,How to pickup file from folder using shellscript. FolderName:/test FileinFolder: test.txt MY req is:Shellscript pickup file from folder and pass file as parameter to java program..? Thanks, Rams (0 Replies)
Discussion started by: ram2s2001
0 Replies

10. Programming

pre defined variables

Hi First I want to explain the scenerio : In my project I want to control the printing of some messages. Thats why I use #ifdef MESSAGE ------------print message-------------- #endif And when I compile the program with -DMESSAGE option, it shows all message and without -DMESSAGE option... (7 Replies)
Discussion started by: sumsin
7 Replies
Login or Register to Ask a Question