BASH- Hold script until all contents of a file is written


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting BASH- Hold script until all contents of a file is written
# 1  
Old 07-11-2014
BASH- Hold script until all contents of a file is written

I have to hit a very large database to pull fields of information.

I have a script that runs multiple instance of the same query against the data base and writes contents to a file.

The script terminates before the file is completely written to confirmed by

Code:
ps -ef | grep <script name>

The code below will hold the script until the file is created.
But I also want to know when writting has completed.

I guess my question is how do I look for EOF ?

Code:
while true 
do 
 [ -f resultfile ] && break
 sleep 2 
done

Thanks alot in advance !
# 2  
Old 07-11-2014
Perhaps you could try using either lsof or fuser to see when whatever process is writing to the file has ceased.
# 3  
Old 07-11-2014
It is the application's job to tell you when it is done. It's very difficult and unreliable to try and detect the other way.
# 4  
Old 07-11-2014
If you can't get the first applicaiton to manipulate a lockfile or otherwise signal your script, you can use incron (a cron like utility for file system events) to signal your second script that it is safe to read.

I use incron to detect the close file event for any file in my public ftp submission directory and as soon as it is done being uploaded, incron launches a script that yanks it away to a non-public directory so that every individual's uploads are private to other users whithout giving everyone a different area.

I also have a web interface to reboot my server, turn on and off anonymous FTP, share or not share my media directories (on/off or for a timeout period), etc. I know very little CGI, so instead of handling it in CGI, I save the state of the user radio button clicks and password hash to a text file and use Incron to detect a change and launch a shell script which parses and interperates it. I did it out of ignorance of CGI but I believe it is very secure.

Mike
This User Gave Thanks to Michael Stora For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash command to find a file and print contents

I need to find a file and print its contents I am trying but it is not working find -path /opt/app-root/src/.npm/_logs -type f -name "*.log" -print Version $ bash -version GNU bash, version 4.4.12(1)-release (x86_64-pc-msys) (1 Reply)
Discussion started by: SVRao19056
1 Replies

2. Shell Programming and Scripting

ksh Script, Reading A File, Grepping A File Contents In Another File

So I'm stumped. First... APOLOGIES... my work is offline in an office that has zero internet connectivity, as required by our client. If need be, I could print out my script attempts and retype them here. But on the off chance... here goes. I have a text file (file_source) of terms, each line... (3 Replies)
Discussion started by: Brusimm
3 Replies

3. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

4. Shell Programming and Scripting

Using sed's hold-space to filter file contents

I wrote an awk script to filter "uninteresting" commands from my ~/.bash_history (I know about HISTIGNORE, but I don't want to exclude these commands from my current session's history, I just want to avoid persisting them across sessions). The history file can contain multi-line entries with... (6 Replies)
Discussion started by: ivanbrennan
6 Replies

5. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

6. Shell Programming and Scripting

Looking for help with parsing file contents in bash [newbie]

Hi I'm just messing around with bash and trying to learn it because I have a course next semester dealing with OS design where we need to know how to use SSH client and either bash or ksh. I've never done shell scripting before. I just started today and I was wondering how parsing files... (1 Reply)
Discussion started by: mehungry
1 Replies

7. Shell Programming and Scripting

Most reliable way to store file contents in an array in bash

Hi Guys, I have a file which has numbers in it separated by newlines as follows: 1.113 1.456 0.556 0.021 -0.541 -0.444 I am using the following code to store these in an array in bash: FILE14=data.txt ARRAY14=(`awk '{print}' $FILE14`) (6 Replies)
Discussion started by: npatwardhan
6 Replies

8. Shell Programming and Scripting

Bash copy file contents into an existing file at a specific location

Hi all I need to copy the entire contents of one file into an existing file at a specific location. I know the exact line number where I need to put it. It appears I would use either sed or awk to do this, but I have been unsuccessful so far: File A line 1 line 2 line 3 line 4 ... (6 Replies)
Discussion started by: gshepherd7
6 Replies

9. Shell Programming and Scripting

Hangman written in Bash. Suggestions please...

qwertyuiop (1 Reply)
Discussion started by: rorey_breaker
1 Replies

10. Shell Programming and Scripting

replacing contents of files from a bash script

I'm writing a shell script and I need to replace the contents of a configuration file based on what is passed to the script...can I replace expressions in a file from a bash shell script? (2 Replies)
Discussion started by: HumanBeanDip
2 Replies
Login or Register to Ask a Question