I am stuck with this requirement. My requirement is that a job will run daily at anytime before and would look for a file named filename.txt in a folder and mv to a different folder and if not found until 9 A.M it will exit with a success code.
Now I did the follwing ..but there is an issue I am having
Now this code works except for one instance when the time passes 9 A.M and the filename.txt doesnot arrive...it keeps looping...i need it to exit..
My code above is a rough one...but mostly it....can you please tell me how to work it out or if there is any other way....
Moderator's Comments:
I have edited your post to add CODE-tags. Please use CODE-tags when posting code(-fragments), file contents or system output. It is easier to read that way and it helps our automated translation service by excluding parts marked this way from automatic translation. Thank you.
Sorry, but the code you posted could never have run. It is crammed full with syntactical errors, which would make it abort immediately. Please post your real code in order to find out what is not working.
Furthermore: this looks suspiciously like homework, for which a separate part of the forum is designated. Please state if this is homework.
Hi Bakunin please take my words this is not a homework and neither I am an unix guy...its just that alongwith some different application i am using this unix application for my project....also i mentioned about the code as a part to explain what I did...i dont have the code handy.....please dont run the code....i just wanted to convey that this is what i did and the problem that I am getting...there is some poblem in my logic when i am coding and thats where i am getting stuck...plz let me know if my explanation answers your question....
To be honest it eludes me what "max_time", "run_time" and "wait_time" do. For your requirement as stated they are completely unnecessary. I have corrected the most obvious syntactic errors but i doubt that this script will do anything useful.
Further, you haven't stated which shell (and, hence, shell programming language) you use, which operating system (this might make a difference on tools like "date") and you still haven't provided the script you actually wrote, but some abstracted thing which never could have run.
My magic crystal globe by which i read minds, correct things i haven't seen yet and generally do wonders is in repair right now, so the bad news is: as long as you are unwilling to give some data to work with i am unable (and unwilling) to help you.
the development envirnement is AIX Unix system....it requires kornshell I suppose....becuase i didn't use bash or c shell....now about he script....please find it below and my apologies for the trouble...current time, max time and wait time are variables I declared....and then I tried using it in the script...but the problem I am facing is when time is after 9 AM the script exits...which is fine...when it is before 9 AM it goes and looks for the file and if it finds it it exits.. which is also fine..and if it doesnot find it loops....it is fine ....but this looping actually keeps continuing if it doesn't find the file even after 9 AM...it only exits after the total max time....it is strange...than within the loop it doesn't recognise the current time...my requirement would be the loop should continue and would exit as soon as it is 9 AM...but it doesn't work the same ...i hope i could explain.....I developed it from some other existing codes....but it would be helpful if you have some other way out.....I have no clue where to fix and if there is some other way out....
Moderator's Comments:
Sigh ... i edited CODE-tags again into your post. I won't do it a third time, but issue infractions instead. If you don't know how to use CODR-tags please refer to the Forums FAQ
Well, "$current_time" is set once (upon start of the script) and then never changes - but after waiting some time "$current_time" doesn't hold the current time any more, but the time at the start of the script. It should be updated with every execution in the loop, though. This is why i have put in the line
as first command within the while-loop, which you have subsequently removed for no known reason. (compare my code and your version of it).
Second, the script will run 5 minutes max, because it terminates whenever "$run_time" reaches the value of "$max_time". "$run_time" is incremented with every execution of the loop and with the fifth execution the line
will evaluate to TRUE and the script will echo "Time out" and exit. If this is desired behavior or not i don't know, but your requirement says nothing about it.
Thanks Bakunin....for your consistent help....I honestly appreciate it....Now about the
current_time=$(date +'%H%M') ...I saw that in your code being mentioned but removed it because I was tellling you my code ..what I had in hand....I will try your code today with the current_time as you said....yes you are right actually about the run_time....it was already there in another code as i said before and I thought to keep it....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. Can you suggest me a code please. Lots of thanks in advance.
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)
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)
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)
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)
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)
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)
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)
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)
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)