File in a folder and loop until time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File in a folder and loop until time
# 8  
Old 05-26-2010
Quote:
Originally Posted by RubinPat
My requirement is simply :A job will run daily at anytime before 9 AM and would look for a file named filename.txt in a folder and if it finds then move it to a different folder and if not found until 9 A.M it will exit with a success code.
Ok, i have commented the code as much as possible to make it obvious what it does.

Code:
#!/bin/ksh

typeset -i iTime=$(date +'%H%M)             # current time
typeset    fFile="/some/file/to/watch"      # file to observe
typeset    fTgt="/some/other/directory"     # target location to put it
typeset -i iInterval=60                     # interval in seconds

while [ $iTime -lt 900 ] ; do               # loop until it is 9:00 am
     if [ -e "$fFile" ] ; then              # if file is found, move it, then exit
          mv "$fFile" "$Tgt"
          print - "File $fFile moved, exiting"
          exit 1
     fi

     sleep $iInterval                       # if file is not found, sleep
     iTime=$(date +'%H%M')                  # update current time
done
                                            # to get here means we never
                                            # encountered the file (otherwise we
                                            # would have left via the "exit 1" above)
                                            # therefore the time must have been up
print - "File $fFile not found but time is up, exiting"
exit 0

I hope this helps.

bakunin
# 9  
Old 05-26-2010
Thanks Bakunin, my own code with the current time inside worked as per my requirement
and also your code I tried and found it better and it also worked.
I need a last suggestion from you ...i just came to know that if the job starts after 9 and
finds the file in the folder
then also it needs to be moved or else it exits and if it starts
before 9 it should look for the file until 9 and then if it finds its ok or else it should exit at 9....
---To be precise
The job starts looks for the file before or after 9
if it finds it moves the file from source to target and exits
If it doesnot find the file and the time is after 9 then it exits
But if it doesnot find the file it and the time is before 9 then looks for the file until 9 and exits

Just that your help is awesome.Thanks

---------- Post updated at 06:43 AM ---------- Previous update was at 06:11 AM ----------

I got it myself...But thanks a ton Bukanin.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create new folder and text file the same time in one line

Is it possible to create new folder and write a new text file in the folder while the current position is outside the new folder? in one line mkdir folder | echo "hello test"> folder/test.txt not work. (1 Reply)
Discussion started by: cmdcmd
1 Replies

2. UNIX for Dummies Questions & Answers

Loop for file merging in a folder

Dear all, I have a few files in a folder (lets say 5) and each have a few lines in them. I want to create merges of each of them with the other ones e.g. I need the following merges I tried to write a loop and started with combinations of 2, I get the write file names but for each... (17 Replies)
Discussion started by: A-V
17 Replies

3. Shell Programming and Scripting

For loop for number of files in a folder

Hi All, Need a for loop which should run for number of files in a folder and should pass the file name as parameter to another shell script for each loop. Please help me. Thanks. (2 Replies)
Discussion started by: chillblue
2 Replies

4. Shell Programming and Scripting

For loop to read folder which are not under processing

Hi, I want to read folders which do not have a file "processing" in a for loop ordered by timestamp. Currently im doing like this. Like cd /home/working for i in `ls -c1` do some command... done I want to exclude folders which have that "processing" file. The directory... (2 Replies)
Discussion started by: chetan.c
2 Replies

5. Shell Programming and Scripting

loop through files in each folder and perform sed

Dear all, I have few log folders in directory (FILE) and i need to perform sed on each files inside each folders. Here is my script, and i wish to rename each file back to the same file name after modification. Can anyone guide me on my script below? eg: folder1 contain files... (2 Replies)
Discussion started by: ymeyaw
2 Replies

6. Shell Programming and Scripting

Loop through text file > Copy Folder > Edit XML files in bulk?

I have a text file which contains lines in this format - it contains 105 lines in total, but I'm just putting 4 here to keep it short: 58571,east_ppl_ppla_por 58788,east_pcy_hd_por 58704,east_pcy_ga_por 58697,east_pcy_pcybs_por It's called id_key.txt I have a sample folder called... (9 Replies)
Discussion started by: biscuitcreek
9 Replies

7. Shell Programming and Scripting

Last modified time of the folder is changing when I view the file inside the directory

Hi., Last modified time of the folder is changing when I view the file inside the directory. Here is the test on sample directory. I believe that ls -l commands gives the time detail w.r.t last modified time. Pl. suggest. bash-3.2$ mkdir test bash-3.2$ cd test bash-3.2$ touch myfile.txt... (2 Replies)
Discussion started by: IND123
2 Replies

8. UNIX for Dummies Questions & Answers

How to append time to folder

Hi i just want to create a folder with current time. For example. foldername_09042010 How do i modify mkdir or write script to do this? (1 Reply)
Discussion started by: pinga123
1 Replies

9. Shell Programming and Scripting

File Management: How do I move all JPGS in a folder structure to a single folder?

This is the file structure: DESKTOP/Root of Photo Folders/Folder1qweqwasdfsd/*jpg DESKTOP/Root of Photo Folders/Folder2asdasdasd/*jpg DESKTOP/Root of Photo Folders/Folder3asdadfhgasdf/*jpg DESKTOP/Root of Photo Folders/Folder4qwetwdfsdfg/*jpg DESKTOP/Root of Photo... (4 Replies)
Discussion started by: guptaxpn
4 Replies

10. Shell Programming and Scripting

Parse the .txt file for folder name and FTP to the corrsponding folder.

Oracle procedure create files on UNIX folder on a regular basis. I need to FTP files onto windows server and place the files, based on their name, in the corresponding folders. File name is as follows: ccyymmddfoldernamefile.txt; Folder Name length could be of any size; however, the prefix and... (3 Replies)
Discussion started by: MeganP
3 Replies
Login or Register to Ask a Question