Wait/if Generated kind of operation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wait/if Generated kind of operation
# 1  
Old 09-02-2014
Wait/if Generated kind of operation

Dear All,

I am running a c++ code that will generate various output files.
After generating each and every file I wanted to process that file and remove using shell.

How can I do that?

example for post script:
Code:
#!/bin/sh
for dirName in ab ac ad ae;
do
    grep -r -n "Max_x"$dirName/file;
    rm $dirName/file;
done

above code will work for completed simulation.

Now lets say I want to run this scritp along with my c++ and do the same.
is there any wait function in shell to do this job?

example:
Code:
#!/bin/sh
for dirName in ab ac ad ae;
do
    wait till $dirName/file to be found
    if($dirName/file found)
    do
        grep -r -n "Max_x"$dirName/file;
        rm $dirName/file;
    done
done


Thanks & Regards,
linuxUser_

Last edited by joeyg; 09-02-2014 at 09:47 AM.. Reason: corrected spelling of title
# 2  
Old 09-02-2014
Hello Linuxuser_

We can use sleep command for put a wait to execute the next process, but it is better you can check the previous command's satus like it is completed or not by a condition as sleep will wait only for mentioned timings by the user. kindly try it and let us know if you face any issues. Also refer man sleep and man test for same too.


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 09-02-2014
Quote:
Originally Posted by RavinderSingh13
Hello Linuxuser_

We can use sleep command for put a wait to execute the next process, but it is better you can check the previous command's satus like it is completed or not by a condition as sleep will wait only for mentioned timings by the user. kindly try it and let us know if you face any issues. Also refer man sleep and man test for same too.


Thanks,
R. Singh
Dear Ravinder,

Thanks for the reply. I will check it out. One quick question based on your reply.
will sleep break from the wait after it satisfies the condition?
I mean, lets say time for generating one new file is 5 hrs and I have given sleep time as 10hrs.will it quit from the loop after finding the required file and restart with sleep time 10 hrs?

Thanks & Regards,
linuxUser_
# 4  
Old 09-02-2014
hi,

you can use this for wait while the file exist,
Code:
while ! [ -e pathOfYourFile ];do sleep 1;done

This User Gave Thanks to protocomm For This Post:
# 5  
Old 09-02-2014
Dear All,

Same type of problem again:

Instead of waiting for file to generate, I want to tell my shell script till one already exist file is getting updated:

Example:
my file will get updated after each and every time as shown below

fileContent (will be updated with time values as shown below after finishing calculations)
Code:
Time = 1E-5
Time = 2E-5
Time = 3E-5
Time = 4E-5
Time = 5E-5
:
:

at time = 1E-5 I want to do some shell operations and I want to tell my shell script that wait till next time to update.
after Time = 2E-5 I want to do again shell operation and wait for next time to update.


Thanks & Regards,
linuxUser_
# 6  
Old 09-02-2014
Hello linuxuser_

Here is an example for same, lets say we have a file name file20 which is being generated daily and we are checking either this is generated or not for today.

Code:
a=10;
while [ $a -le $a ]
do
 if [[ -f file20 ]]
 then
  echo "File20 has been created."
  break;
 else
  sleep 120 ## Taking 2 mins sleep here
 fi
done

Just want to add here we can run this script in background because this is a infinite loop so it will be keep on running till it will see that file20 is being created. So we can schedule this to run in a day at crontab and when it sees the flle accordingly we can set script to send an email to a list to notify on same.

Please let me know if you have any queries. Also please don't try this at Live environment, first try this at non live or test environments.


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 7  
Old 09-02-2014
Dear Ravinder,

Thanks a lot for your knowledge.
I need a check little different way. I have a file with name say file30.
This fill content will vary with time. Like push_back type of writing.
after finishing 1st iteration it will contain
Code:
Time = 1

after 2nd iteration it will have
Code:
Time = 1
Time = 2

and so-on.

I want to check whether new time is updated or not.

How can I do that?

Regards,
linuxUser_
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

calling a shell script in background and wait using "wait" in while loop

Hi, I am facing a strange issue, when i call a script from my while loop in background it doesnt go in background, despite the wait i put below the whil loop it goes forward even before the process put in background is completed. cat abc.txt | while read -u4 line do #if line contains #... (2 Replies)
Discussion started by: mihirvora16
2 Replies

2. Cybersecurity

What kind of hacking is going on here??

Connecting to the Internet with OpenVPN, the connection fails. Rerunning openvpn works second time round but the install is hacked at that point (e.g., a rogue 'java-security' update tries to install itself on 'yum update', yum however spots this and rejects the download, other basic things start... (3 Replies)
Discussion started by: GSO
3 Replies

3. Shell Programming and Scripting

Column operation : cosne and sine operation

I have a txt file with several columns and i want to peform an operation on two columns and output it to a new txt file . file.txt 900.00000 1 1 1 500.00000 500.00000 100000.000 4 4 1.45257346E-07 899.10834 ... (4 Replies)
Discussion started by: shashi792
4 Replies

4. Programming

A different kind of counting in SQL

I am looking to do a count on a database table where some of the elements count double. Say the data is as follows: id value 1 X 2 Y 3 X 4 X 5 Y A regular count (SELECT value, COUNT(*) FROM data GROUP BY value) would yield: X 3 Y 2 However, Y happens to count double so the answer should... (2 Replies)
Discussion started by: figaro
2 Replies

5. Infrastructure Monitoring

sed help,,kind of urgent!!

Hello All, My problem is: I want to replace a line from a file with sed. The first word in that line is always the same in every server. The second line is server model, which of course will vary from platform to platform and I need to leave that word as it is. After the second word, I need to... (3 Replies)
Discussion started by: solaix14
3 Replies

6. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies

7. UNIX for Dummies Questions & Answers

What kind of Linux for the newbies?

I am one of the newbies. I want to load linux on my notebook, however, i am not sure which linux is the most recommend for the newbies. Could you please advise? Thanks you very much for any advise you may give me. Best Regards, SANLEN (2 Replies)
Discussion started by: sanlen
2 Replies

8. Shell Programming and Scripting

Need to execute 2 scripts, wait, execute 2 more wait, till end of file

:cool: I need to execute a shell script to do the following: cat a file run two back ground processes using the first two values from the file wait till those background processes finish run two more background processes using the next two values from the file wait till those background... (1 Reply)
Discussion started by: halo98
1 Replies

9. UNIX for Dummies Questions & Answers

Kind of weird question

I recently purchased a book titled Hacking: The Art of Exploitation. When I got it home I read the preface and found out that i shouldnt have bought it. It says the code examples in this book were done on an x86 based computer (I have a mac). Is there anything I can do to make my mac run similar to... (2 Replies)
Discussion started by: Cyberaxe
2 Replies

10. UNIX for Dummies Questions & Answers

what kind of UNIX

ok, so i want to figure out what type of UNIX i have and in this book im reading about it, it says that i can figure out what type i have by typing the command uname in the prompt. So i did this and it came up saying Darwin?? is that part of System V UNIX or BSD or do i have LINUX? if anyone can... (2 Replies)
Discussion started by: hiei
2 Replies
Login or Register to Ask a Question