Wait/if Generated kind of operation


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

Could you please let me know the following points.

i- Contents are updating daily in a sngle file or after creating a backup of old file it is creating a new one like as follows.
file_yesterday, file_today OR there is only 1 file.

ii- Also what is the time period when file is being updated? Is it a daily a fixed time task or not?

Also please add more information if there any it will help us to understand your actual requirement.

Thanks,
R. Singh
# 9  
Old 09-02-2014
file content after 1st iteration

Code:
Time = 1

file content after 2nd iteration

Code:
Time = 1
Time = 2

file content after 3rd iteration

Code:
Time = 1
Time = 2
Time = 3

file content after 4th iteration

Code:
Time = 1
Time = 2
Time = 3
Time = 4


and so-on.
Hope it will clear all your questions.
Hint is I always have to search for last Time value and compare with previous value. If its get updated have to do some shell operations.

Regards
linuxUser_
# 10  
Old 09-02-2014
Hello linuxuser_

You can use the following code for same. This is also an example of infinite loop which will break when it's condition gets satisfied(means file is being updated). Please run this in background and you can set it to crontab as per your need like 2 hours or 4 hours difference.

Code:
a=10;
cp -p file11 /tmp/file1 ## created copy of file at tmp
while [ $a -le $a ]
do
## comparing the values of files present in directory and in tmp ##

 value=`diff /tmp/file1 file11` 
  if [[ -n $value ]]
  then
   echo "file has been updated."
   rm /tmp/file1
   break;
  else
   sleep 120
  fi
done

Please let us know if you have any queries.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 11  
Old 09-02-2014
Thanks a lot Smilie
One very quick question:
will sleep 120 allow shell to check for the condition in mean time or it will make shell to sleep for 120 minutes?

In other way how should I come-up with correct value for sleep time? or its independent of time?

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

you can put sleep timings as per your wish lets say it is 2 mins then again it will check the condition either file has been updated or not if yes it will come out of loop else it will start sleep process again. So we need not to worry about condition check as it will happen only thing this sleep process will make us to set the time period like after how much time we need script to check about file's status. But if you will put less minutes lets say 1 min then it will keep server occupy to check the file status in every one min so better we can mention 5 mins or so(as per your wish as you would have better idea about file's updating timings) so that it will not occupy server that much which it will do when we will keep 1 min interval.


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

Need little help regarding the same problem.
Finally I got one conclusion that I should be able to read time value from the output file that will get update after every time step.

file format after some iterations:
Code:
Time = 0

xMin = 0.0
yMin = 0.0
xMax = 1.0
yMax = 1.0

Time = 1

xMin = 0.01
yMin = 0.01
xMax = 0.98
yMax = 0.899

Time = 2

xMin = 0.19
yMin = 0.25
xMax = 0.795
yMax = 0.9878

Time = 3

I want to read last time or last but-one depends on existence of some file for particular time step.
Can you help me?

Regards,
linuxUser_
# 14  
Old 09-03-2014
Dear linuxuser_

Could you please be more clear on your requirement, as I understood you are requesting for checking a file's existance. Let me give you an example for same.

Code:
if [[ -f "file2" ]] 
then 
echo 
"file2 is present."
else 
echo "file2 is NOT present." 
fi

In my case file is present so it will give following output. Also please refer man test for more information. Hope this helps.

Code:
file2 is present.

Thanks,
R. Singh
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