The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Lock a file from being deleted? Darren Taylor Shell Programming and Scripting 3 03-10-2008 06:07 AM
Lock File canman UNIX for Dummies Questions & Answers 4 05-06-2005 06:28 AM
how to lock keyboard without using lock command dianayun UNIX for Dummies Questions & Answers 7 06-21-2002 07:05 PM
lock file! sskb UNIX for Dummies Questions & Answers 4 10-24-2001 06:10 PM
How to lock a file in unix? tammy_schmuki UNIX for Dummies Questions & Answers 1 05-25-2001 01:00 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 09-16-2008
baivab baivab is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 9
Question Writing to file failing (maybe due to lock?)

Driver script kicks off supporter scripts in background.
The supporter script writes it's own PID ($$) into a status file. When script completes, deletes the PID from the status file.
Quote:
echo $PID >> $STATUS
##blah...blah
sed '/'$PID'/d' $STATUS > $STATUS.$$
mv $STATUS.$$ $STATUS
The driver script constantly polls this status file for number of lines. As and when it's get lower than XX number of lines, fires off another supporter script in background. This continues till all supporter scripts have started and then the driver program just waits for the $Status file line count to go to zero and stops.
Problem:
+++++++++++
I am echoing putting the $PID into Status file and removal too. I am seeing both in nohup.out. However, VERY, VERY ERRATICALLY sometimes although the echo statements on removal success are present, the $STATUS file still shows the PID! I checked and also determined these PIDs are indeed unique. Why is it that although the sed command runs successfully (the echo on removal is after the sed command with a if .. $? -eq 0 clause) the actual delete do not happen? Is it because at that point in time 2 or more background processes are "attacking" the $STATUS file and somehow sed fails to recognize it? What can be done to ensure that the sed command really does delete the entry, i.e. obtain a file lock/handle, etc. I think it's obvious, but the STATUS file is common.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0