Troubleshooting: file reading clash?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Troubleshooting: file reading clash?
# 1  
Old 10-03-2006
Troubleshooting: file reading clash?

Hi all
I´m trying to fully understand an issue I had yesterday and was just hoping you'd give me your opinion about it. I believe I fixed the problem but I still feel ignorant about some parts of the behaviour I could experience in the following scenario. Here was the situation (old simplified code version):

Code:
for FILE in $INPUT_DIR ; do
   grep -q $FILE $PROCESSED 2>&1
   if [ $? != 0 ] ; then
      echo $FILE >> $PROCESSED
   else
      continue
   fi
   SOURCE=`grep ^S $FILE | wc -l | awk '{print $1}'`
   END_RCD=`grep ^E $FILE | wc -l | awk '{print $1}'`
   if [ $SOURCE -ne $END_RCD ] ; then
      echo "Error in $FILE: "$SOURCE" source keys detected, but "$END_RCD" end keys detected.
   fi
done

The content of the INPUT_DIR contained a lot of files, and it reported the above error on one of them (SOURCE = 1, END_RCD = 0). However the file was ok as far as I could see. I quickly ensured my commands were correct and even re-ran the script on the whole file list to get a final ok as an output, so this looked weird at first sight.

After some time of investigation I finally found that I had a bunch of n processes running in the background calling that bit of code. Despite of this I originally supposed this script would only be running once at the same time, so the files processed from my process(n) falling into INPUT_DIR would be updating the PROCESSED file so they don't get picked up by the next calls.

Unfortunately for my theory, the truth was that the script got called several times at the same time (from different sessions), processing in parallel, this with a PROCESSED file that wasn't unique (you begin to see what it can look like here). So to summarize, the above script reported an error when running on the process (n) for a file created by the process(n-1).

Now the above situation should still be ok as long as a file is opened once a time, it's just that this file gets checked by the wrong process but the result remains the same. So what I believe is that the file on which it reported the error was opened in two sessions at the same time.

I have removed the PROCESSED file and now run this script once after all processes are completed so I don't get any issue anymore. The only thing I still don't understand is why END_RCD gave 0. Since two sessions have different variable buffers, I don't see how a potential clash on a file would produce such an error. If anybody here has a credible Smilie explanation, I would be very happy to know about it.

Many thanks,
Yann
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

3. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

4. UNIX for Advanced & Expert Users

What is a file handle? for NFS troubleshooting stale issue.

Experts, Can any one please explain about a "File Handle" , what it is. Can we see it, like an inode number. - Also what is the significance of it in "Stale NFS file handle" error. Thanks, (3 Replies)
Discussion started by: rveri
3 Replies

5. Shell Programming and Scripting

Reading UNIX commands from file and redirecting output to a file

Hi All I have written the following script: #!/bin/ksh while read cmdline do echo `$cmdline` pid="$cmdline" done<commands.txt =========== commands.txt contains: ps -ef | grep abc | grep xyz |awk '{print $2}; My objective is to store the o/p of the command in a variable and do... (8 Replies)
Discussion started by: rahulparo
8 Replies

6. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

7. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies
Login or Register to Ask a Question